I am facing an issue in ExtJS with the Date format.
I'm using Ext.Date.format(value, 'm/d/Y h:i:s a') where the value is a date from the database.
While saving a Date 06/29/2018 12:15:00 am to DB it's storing as 2018-06-26 07:30:00
I am getting the Date from Database as 2018-06-28T18:45:00.000Z when converting to Ext.Date.format it changes to 06/29/2018 12:15:00 am.
I need store the date to be same as UI(06/29/2018 12:15:00 am) in db. Is there anyway?
Thanks
The reason might not be ExtJS itself nor your database, but the fact that your server and browser are on different timezones (i.e. Server in USA and browsing in Europe). I can think of two solutions:
1) Store the timezones in the database along with the dates. The record would look something like this: 2018-06-28T18:45:00.000Z+10:00. Use .NET's DateTimeOffset type in your C# code for this alternative.
2) What you can do instead is to convert all dates to UTC in the server side. Probably calling DateTime.ToUniversalTime() will suffice, but you can see this answer for more details.
Then you can use a library like moment.js which helps a lot with date and time manipulation/formatting to display the dates in the user's local timezone.
Related
I have a:
Field in my store as date with dateFormat set to 'Y-m-d'
Column in my grid (datecolumn) - format set to 'Y-m-d'
Editor on Column (datefield editor) - format set to 'Y-m-d'
Postgresql Table with a date column (Note, not a timestamp or timestamptz, but date)
I have data that comes into the store from Postgresql like:
{
mydatefield: "2021-07-30"
}
Now, the date do dispay is 100% correct in the grid. Problem comes in when I select a new date, through the datefield editor, let's say
2021-07-31
The moment it saves back to the server it passes:
mydatefield: '2021-07-30T22:00:00.000Z'
and the server saves it wrong as '2021-07-30' and the grid refreshes back to 2021-07-30.
We are on South African Standard Time (+2) Do not know if it something to do with Daylight Saving
So, to recap. It does not matter what date I select, it keeps saving a day less than the day I selected.
The date it's saving is in UTC, which is the timezone you ought to be using on your server(s) and database(s) - that's a good thing as it removes timezone related info and allows dates to be localized to any timezone.
When you transmit date values over the wire between the server and the browser, make sure you're using RFC-8701 formatted strings (what you get when you call new Date().toJSON() in JavaScript). Then you won't have to worry about timezone issues, as RFC-8701 dates are always in UTC. The browser will take care of transforming dates to local time - just call new Date(myRfcDateString).
More info: Storing date/times as UTC in database
Use convert method of store to process data for date column before storing it in store data. Then the store data will be submitted to server in proper format.
There was similar question asked, links below -
Question - Datefield in grid editor
Fiddle - https://fiddle.sencha.com/#view/editor&fiddle/2e0a
I'm developing a Clio integration with access to the calendar, but there's been an issue with dates. While the documentation says they expect an ISO-8601 timestamp date, it seems like there's something adding offset to the timezone value in dates being sent to the system.
For example, if I send a date 2018-05-17T23:59:59.999999-04:00 on both start_at and end_at properties when creating a calendar entry for an all day event, the value returned when fetching this entry through the API is 2018-05-17T17:00:00-07:00, which is clearly wrong. Am I missing something here?
The expected result should be something like either 2018-05-17T23:59:59-04:00 or 2018-05-18T03:59:59Z if milliseconds are ignored.
All dates are based on UTC timezone. Could it be that your site/server/script is set to a local timezone and so the dates are off for part of the day?
Try setting your scripting environment to UTC time before making any date/time-based queries.
I'm using Seekwell to connect my AWS postgres database to Sheets.
I think I'm converting my dates to standard 'date' (YYYY-MM-DD) format in the code, eg.
date(date_trunc('day', u.created_at::date)) Date_Created
However, when the query is run, my dates are iso 8601, eg.
2018-05-16T00:00:00.000Z
Of course, given that my results are going into Google Sheets, I can always convert those dates there in sheets, but that adds a layer of complexity that is hard to manage.
How can I make sure the dates are formatted correctly before the results land in sheets?
Michael from Seekwell tells me this is:
a bit of bug with how JDBC handles dates in the background. You're on Postgres, right? This should work from within the add-on:
to_char(your_date_column, 'YYYY-MM-DD')
Sheets will recognize that result as a date.
This worked.
I like to save the current DateTime.Now for the current user as UTC. For any user the time is than relative to each other ? I used this code snippet to realize UTC for the Entity Framework:
Entity Framework DateTime and UTC
After a look into the database the column for the date has not changed.
09.05.2014 20:21:24
I need to show on the client side the date relative to each user. So when the user created his account in America 14:00 I like to see in Europe 20:00.
First of all you need to use DateTime.UtcNow instead of DateTime.Now. EF will save date as it is, it will not do anything.
For database, it is just a date, whether it is UTC or specific time zone, database has no idea. It is only when we retrieve date from database, before displaying it to local user, we should call ToLocalTime or similar method in client UI library to convert UTC into localtime. ToLocalTime assumes that input is actually UTC.
If you are saving date from client side, for example with AJAX post in JavaScript, JavaScript dates should be serialized as UTC.
Remember that server has no idea from where you are sending date, server cannot convert any date to UTC, client on other hand has complete idea of which country and which timezone it is set at and it can easily convert local time into UTC.
Calling .ToLocalTime() on a DateTime object will convert it to the local time. You should always Save the date as UTC then convert upon display.
I have various timestamps stored in Mongo collections, some as floats and some as ints.
They are all stored in BST and the server will be switched to UTC soon. How do I convert them within Mongo to be UTC timestamps?
In MySQL I can do this:
UPDATE `table` SET `field` = CONVERT_TZ(`field`, 'Europe/London', 'UTC');
Is there a Mongo equivalent?
You'll have to use your language of choice and update them one at a time. It should be as simple as a for loop that loads the data and rewrites it.
Just double-check how your language of choice handles timestamps across timezones. Making such a data change can have all kinds of unexpected effects on production code.
Timestamps are generally in UTC and not in a specific timezone. All date/time libraries I've worked with return timestamps that are the number of seconds (or milliseconds) since Jan 1st 1970 UTC. Check the documentation for the library you used to create the timestamp to be sure.
This means that you should be ok, unless you have used a date/time library that does not follow this convention, or somehow calculated the timestamps yourself and accounted for the timezone.
For example in JavaScript if you store the value returned from new Date().getTime() and later pass that value to new Date(...) on a different system you will end up with the same absolute date/time, regardless of the timezones of the two systems. The same goes for Ruby, do Time.new.to_i on one machine, and run Time.at(...) on another and you will get the same absolute date/time. When I say "absolute date/time" I mean that it's UTC time will be the same, most likely the system will display it in the local time zone, but that is what you want.
Some points to consider about date in Mongo:
All dates are stored in UTC in MongoDB
MongoDB stores dates internally as a 64 bit integer representing
milliseconds since 1970-01-01T00:00:00Z
If the date value you provide is not already in UTC it
will be converted to UTC before being stored in MongoDB by the driver
The recommendation is not to use DateTime.Parse.
You will get into all sorts timezone issues regarding how DateTimes are formatted.
Instead just use one of the DateTime constructors with UTC flavor.
Example:
var dateTime = new DateTime(2011, 5, 5, 0, 0, 0, DateTimeKind.Utc);
Hope you find it useful.