Get created_at with millisecond precision from database in Laravel - laravel-5

I am using Laravel 5.1. I want to get milliseconds precision for created_at that I get from the database.
I have tried the solution given for this question. But there isn't any change. Also I tried raw query. Still I get only up to seconds. Is there any way to get millisecond precision?

It may be a problem about your column type. Assuming you are using MySQL, you should manually add (or modify) a column with type TIMESTAMP(3) on your table:
\DB::statement("ALTER TABLE `my_table` ADD COLUMN my_col TIMESTAMP(3) NULL");
More information here: https://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html

Related

HybridRelations laravel mongo is really slow

Used HybridRelations to store user notifications in mongoDB instead of mysql and imported 3million records and now user->notifications()->take(5)->get() or user->notifications()->paginate(5) takes over 30 seconds.
any idea how to speed it up?
on mysql with same amount of records it took 200 milliseconds.
notificaiton model has user_id and description and priority and read flag and user_id is set as an index.
Maybe this suggestion can help you.
When use user->notifications() means the query like that
db.notificaiton.find( {"user_id": <?> } )
That will get all record by user_id.
You can dump the user->notifications() and check. That should be Collection type and contains more than 5 records.
The solution is this.
You can write specific method to ensure what your mongo query expression.
The problem was the column that you are sorting by should be an index as well as the columns you use where clause on.

Change column type, Laravel

I have a column $table->date('start_date'); , and I want to store data and time so I will need timestamp.
I already have some date in my current table, so I am not sure what to do without deleting existing data.
I find some solutions (on changing data type) that involve doctrine, but from what I read, Supported Laravel Versions is 6.x and I am using 7.
Any solutions?
According to the PostgreSQL documentation you can convert a date to timestamp by using to_timestamp() function
https://www.postgresql.org/docs/8.2/functions-formatting.html
You have two choices :
Create a new column and create a script which convert all entries in the right format
Create a script which update all the datas you need to into the already existing table

Parse.com : query with two datetime at different column

I want to build sync method, both from my local database to parse.com and from parse.com to my local database. For first case ( from local to parse.com, Alhamdulillah my script run well. But for second case, i need query between column last_update and last_sync (i do not use updatedAt caused by i can't control it, so i use last_update).
Please explain me how to get all data if last_update is greaterThan last_sync?
From https://www.parse.com/questions/querying-between-two-dates i got query between two dates, but it's from same column, the value of query is real value. But my case, the value of key = last_update is column name, last_sync.
Thank you...
You can't use a query constraint that compares two columns. You need to change your logic. Why do you store both a last_update and last_sync in a record?
Syncing is a complex subject and you can easily mess up the logic. I don't understand how you can store a last_sync date on every record, as this has to be different for every user. You need to store the last_sync value for each user, and use that to compare against the last_update column on all records.

Updating date field using Hibernate - Row not updated if date is the same, time is different

I have a situation where a table in the database has a date field defined as date where time also is important (for sorting later).
At first, all times for the date where coming as 000000 but I updated the code to use timestamp and when inserting new records, it's working fine.
Update on the other hand will not change the database if the date is the same (but different time). Apparently, while inserting, hibernate doesn't take into consideration the time and the record is not change (or at least this is what I discovered from my testing).
I can't change the database structure to use timestamp or add a time field.
Any help is really appreciated :)
Thanks

Oracle - Fetch date/time in milliseconds from DATE datatype field

I have last_update_date column defined as DATE field
I want to get time in milliseconds.
Currently I have:
TO_CHAR(last_update_date,'YYYY-DD-MM hh:mi:ss am')
But I want to get milliseconds as well.
I googled a bit and think DATE fields will not have milliseconds. only TIMESTAMP fields will.
Is there any way to get milliseconds? I do not have option to change data type for the field.
DATE fields on Oracle only store the data down to a second so there is no way to provide anything more precise than that. If you want more precision, you must use another type such as TIMESTAMP.
Here is a link to another SO question regarding Oracle date and time precision.
As RC says, the DATE type only supports a granularity down to the second.
If converting to TIMESTAMP is truly not an option then how about the addition of another numerical column that just holds the milliseconds?
This option would be more cumbersome to deal with than a TIMESTAMP column but it could be workable if converting the type is not possible.
In a similar situation where I couldn't change the fields in a table, (Couldn't afford to 'break' third party software,) but needed sub-second precision, I added a 1:1 supplemental table, and an after insert trigger on the original table to post the timestamp into the supplemental table.
If you only need to know the ORDER of records being added within the same second, you could do the same thing, only using a sequence as a data source for the supplemental field.

Resources