In my PostgreSQL database, the datetime stored as 2022-05-10 10:44:19+08 and when I get
the datetime by using the sequelize, it will give in format:: 2022-05-10T02:44:19.000Z.
So, my question is how to convert to 2022-05-10 10:44:19 ?
Thanks in advance.
There is a direct dependence on the time of your server. Therefore, depending on what you want to get, you can use different options.
Here is a dbfiddle with examples
Related
I am trying to read some data from the SharePoint API via the older _vti_bin/client.svc endpoint
I can't seem to find what type of date format this is and how I can parse it via C#.
The timestamp being returned is:
"LastContentModifiedDate": "/Date(2022,3,18,13,12,28,990)/"
The year and month are obvious so I could parse it myself if I knew what all the values are. Is there a formal definition for this or a way to parse this reliably? Is this a DateTime or DateTimeOffset or something else?
I just get an exception when trying to deserialize to a DateTime or DateTimeOffset.
The /Date(...)/ format is Microsoft's built-in JSON date format.
You can try to parse it using the code below.You can also check out this post, which provides a lot of methods.
using System.Web.Script.Serialization;
//code
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
DateTime ddate = json_serializer.Deserialize<DateTime>(#"""\/Date(1326038400000)\/""").ToLocalTime();
I want to save my timestamp in following format with TypeORM on NestJS
Date formats should be YYYY-MM-DDTHH:MM:SS+01:00 or YYYY-MM-DDTHH:MM:SS.sss+01:00
If you use new Date() you will get the same format you mention above. You can also use the package moment,js.
I have a query that works fine in mongodb compass, but the moment I bring it over into Jupyter it breaks. The issue is something to do with the date filter.
I have tried both:
cursor = prod_db.my_collection.find({"date": {"$eq": "new Date('2021-04-26')"}, "type": "Regular"})
as well as
cursor = prod_db.my_collection.find({"date": "new Date('2021-04-26')", "type": "Regular"})
If I remove the date query, I get a return that I would expect, which validates that the db connection is set up properly and that the "type" filter is valid. What am I missing here?
new Date is the date keyword for MongoShell.
You should replace it with python's built-in datetime package.
from datetime import datetime
cursor = prod_db.my_collection.find({"date": datetime(2021, 4, 26), "type": "Regular"})
Issues mapping date columns across python and Mongo happens primarily because Mongo stores the date as a JavaScript date object and then wraps the ISODate format around it. However if the date values that we are trying to pass from python onto mongo is in datetime format ( like #hhharsha36 mentioned above) one should be good
I found this article helpful when I was going through some hellish time using dates from pandas and python variables and using that to query/insert/update in Mongo : (https://medium.com/nerd-for-tech/how-to-prepare-a-python-date-object-to-be-inserted-into-mongodb-and-run-queries-by-dates-and-range-bc0da03ea0b2)
I am using python3 and I have a time data format like '01-FEB-17' and I need to parse it with datetime.strptime. Does anyone know which format is the correct for this? I tried '%d-%b-%Y', '%d-%m-%Y',... and none of them worked.
Thanks
You can use this
from datetime import datetime
t = datetime.strptime('01-FEB-17', '%d-%b-%y')
NOTE: You can head here for a full list of format specifiers to use
in Mongodocs, it is said that datetimes with specified "Z" timezone at the end are saved as "UTC" datetime format..
https://docs.mongodb.com/manual/reference/method/Date/
I created some sample time data in Python:
now=str((datetime.datetime.now()).isoformat())+'Z'
then=str((datetime.datetime.utcnow()+datetime.timedelta(0,one_week_in_seconds)).isoformat())+'Z'
I used datetime.now() and datetime.utcnow() and appended 'Z' on both...
this is what I get:
'now': '2018-07-10T11:06:05.512484Z',
'then': '2018-07-17T09:06:05.512484Z',
I am now using MEAN stack with Node/Express and mongoose (ODM) Driver to make my schema models in the database. When I push the data via some router middleware to my mongoDB Database, the two fields have mongoose "Date" format. However, for both fields it creates an ISODate time format...:
"now" : ISODate("2018-07-10T09:02:01.410Z"),
"then" : ISODate("2018-07-17T09:02:01.410Z"),
I think thats a bug, normally, if "Z" is specified, it should create the specified time in ISO-Format, which it is here, but as I have created the time in local-time format and appended a "Z" in the first case ("now"), the time should be saved as 'now' : ISODate("2018-07-10T11:06:05.512484Z") without modifying /
converting from local to UTC time or not?
if you want to save specific country timezone and if you are using moment then it is easy to manage
below link will help to you
Updating time offset with moment().utcOffset()