I have a server application that is making calls to a google spreadsheet to write some values. What is the safest format I should use to write a date to a spreadsheet safely so it is interpreted as a (date)time appropriately ?
For instance if my application writes a date in the iso format 8601 format, the date won't be parsed by google spreadsheet, 2019-06-11T15:57:30+02:00 is interpreted as text and then I would need to resort to questions like this one.
On the opposite, writing 2019-06-11 15:57:30 does work, yet I am losing the information of the time zone, and the actual time I wanted to write was 2019-06-11 13:57:30 +0.
What format should I use to write DateTime objects in Google spreadsheets?
Do you recommend systematically converting to UTC and then applying format like YYYY-MM-DD HH:MM:SS +TZ?
I want to highlight that I'm working in an international context, (mainly in France) and I want to avoid confusing formats (like dd-mm-yyyy vs mm-dd-yyyy) and retain timezone information if possible.
Had the same problem some time ago.
Unfortunately G-Sheets does not recognize timezones in the date/time fields. If you do need it for processing, you need to store it as a text, or UTC time + another column for the time zone.
Related
I have a react app which uses firebase cloud functions. On the client side, I use pure javascript Date.now() to get the local time (PST timezone) of the client.
On server size, I also try to use the same approach to get the timestamp, but it is in different timezone. This will introduce an issue that if PST time is 8:15pm 12/07/2019, it will be 4:15am 12/08/2019, the date is different.
In this case, how can I keep the timestamp consistent between client and server side? Thanks!
There is no timezone data encoded into javascript Date objects or Firestore Timestamp object. Date objects represent time in terms of unix epoch time, which represents a specific point in time for all people on the planet. (Definitely learn what that is if you don't already.)
What you're likely doing is printing a string representation of the date, and it's being formatted the host's configured timezone. Since you haven't shown any code, it's impossible to say for sure, but it's a fact that Dates don't have a timezone.
If you want to format a date with a specific timezone, you should use a date formatting library that lets you specify which timezone should be represented in the string format.
According to this article, it's best to convert Date into Epoch time in order to use it is range query in DocumentDB. However, as recently the range query on Sting values has been added to DocumentDB, it is necessary to do convert date-time to epoch (as long as all date-time values have the same format and are in UTC format)?
This is similar to this question, where the accepted answer suggests using strings as you point out.
But to answer your question more specifically, DocumentDB cannot store JavaScript Date objects because it only stores pure JSON and Date is not a part of the JSON spec. So, you (or your client API) needs to do something with Date objects. By default, the node.js and .NET clients will convert Date objects to ISO-8601 formatted strings so using strings is actually a bit easier than Epoch. Just send the Date object to the database. The one trick to keep in mind here is that it's not converted back into a Date object when you read it. It comes back as a string. You have to do the conversion yourself. In JavaScript, this is easy. Just call new Date(yourDateString). Not sure about .NET or the other platforms.
This question already has answers here:
moment.js - UTC does not work as i expect it
(2 answers)
Closed 8 years ago.
I have gone through the documentation and am a tiny bit confused about how to proceed.
There are similar questions, but none talk about parsing particular dates received in formats and swapping between local and utc dates.
I receive a local datetime, local datetime format and need to generate utc datetime from it in a particular format and this is how I think I should do it. moment(dateTime,localDateTimeFormat).utc().format(specifiedFormat);
I receive utc datetime in a particular format and have to generate locale specific datetime in a particular format. How do i do it?
moment.utc(utcDateTime, utcDateTimeFormat).toDate(); gives me javascript date i believe. How do I format it then?? Do I have to create a new moment using the generated Date object?
Another thing I could do would be getting the timezone and then formatting. I wonder if I am taking the wrong route here. Please help.
On Item 1 - Yes, that's one way to do it. However, if the output format is just going to be an ISO8601 UTC timestamp, then you can call toISOString directly on the original moment. Since UTC is implied by the output, it would be redundant to call utc() again.
On Item 2 - Just like the utc() function, there's also a local() function. Once you have a moment object, you can use toDate or format or any other of the functions described in the documentation. No, you do not need to create a new moment using the generated date object.
moment.utc(utcDateTime, utcDateTimeFormat).local().format(specifiedFormat)
Again, there's more than one way to do things here. If the utcDateTime is already in ISO8601 format, and contains either a Z or an offset like -01:00, then that will be taken into account and you can simply do this:
moment(utcDateTime).format(specifiedFormat)
On the last item you mentioned about time zones, it's difficult to tell what you are asking. You should elaborate with specific details in a new question.
The program I am currently designing use the dd/mm/yyyy date format, while Sqlite standard format is yyyy-mm-dd. My program make use of quite a lot of date calculations using julianday('yyyy-mm-dd'). I know I could convert the dd/mm/yyyy format to yyyy-mm-dd by using SUBSTR(X,Y) manipulation or by using the code of the language I am designing the db front-end; but i wish to avoid those. Any Idea?
You should always store dates (and timestamps) using native date format that is provided by database engine for following reasons:
Native formats permit native date arithmetic functions to work.
Native formats permit indexes to be consistently applicable, so you can use date comparisons efficiently and use operators like BETWEEN.
Native formats take less space to store on disk. For SQLite, storing date as real number of days from 4174 BC or as integer number of seconds since Jan 1st, 1970 takes 8 bytes. For your representation, it will take at least 10 bytes.
While SQLite does not really have true native date/datetime type (which is big omission in my opinion), it does have 3 permissible formats: TEXT, REAL or INTEGER that are still treated (to some extent) as native datetime formats, and all advantages outlined above still apply.
When you need to display dates in your application, you should use libraries provided by your scripting or other programming languages that know how to display dates in desired format.
In other words, use database to store, compare and retrieve data, and use your application to render it in desired format.
Just getting into SQLite and I understand it does not use datatypes the same way as other languages.
I'm building a database and it has to store date and time quite a lot. And I've read a lot about the date and time functions, etc, but I just want to make sure that in my CREATE script I shouldn't have anything other than
BirthDate TEXT
DateTime TEXT
I'm not sure exactly what your question is, but I think the below excerpt may prove to be useful (taken from http://www.sqlite.org/datatype3.html):
SQLite does not have a storage class set aside for storing dates
and/or times. Instead, the built-in Date And Time Functions of SQLite
are capable of storing dates and times as TEXT, REAL, or INTEGER
values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November
24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these
formats and freely convert between formats using the built-in date and
time functions.