I have a Postgres database. In a table I have a column of type „date“.
I try to insert into this db with node express
Let myDate = "2022-03-03";
DB.query("INSERT INTO mytable (mydate) VALUES ($1)", [myDate]);
But the date in the database is then "2022-03-02". Looks like node is doing some kind of date to datetime conversion and then depending on the timezone reconvert it (because my timezone is 1h behind UTC)
So who can explain what is going on and how to handle this correct?
Related
I am storing a date in mongodb using mongose with the help of moment js.
I am creating the date object from a date string which is in the format MM/DD/YYYY.
below is how i assign the date
const startDate = momentTz(
data.startDate,
"MM/DD/YYYY",
"Asia/Kolkata"
).startOf("day");
but ever time I assign this date object to the mongoose model while creating a document it is storing as 2022-11-30T18:30:00.000+00:00 ie, the time is being automatically set to 18:30.
how can i set this to the start of the day.
Use this one:
const startDate = momentTz(
data.startDate,
"MM/DD/YYYY",
"Asia/Kolkata"
).startOf("day").toDate();
MongoDB stores Date values as UTC times - always and only. It is the client responsibility to display the date/time in local time zone and format.
MongoDB stores dates as BSON type 9, which stores the number of milliseconds since 1970-01-01 00:00 UTC.
18:30 UTC is midnight in Kolkata, so that date/time is correctly showing the start of the day 2022-11-31 IST.
It is up to the client program to convert from UTC to a different timezone if that is desired.
I have excel which i am trying to import in oracle database table.
Some of the values in excel consist of for example 14:39.5 with double colon. What dataype in oracle database table i should provide to store this value ?
Currently have given varchar datatype and its throwing an error during import as :
Conversion error! Value: "00:12:01.615518000" to data type: "Number". Row ignored! Value is '00:12:01.615518000'. Cannot be converted to a decimal number object. Valid format: 'Unformatted'
You can store it as an INTERVAL DAY(0) TO SECOND(9) data type:
CREATE TABLE table_name (
time INTERVAL DAY(0) TO SECOND(9)
);
Then you can use TO_DSINTERVAL passing your value with '0 ' prepended to the start:
INSERT INTO table_name (time)
VALUES ( TO_DSINTERVAL('0 ' || '00:12:01.615518000') );
db<>fiddle here
If it is part of a date/time stamp then you could store it as DATE or TIMESTAMP if you could add the date component. Oracle doesn't have just a TIME data type.
If you can't add a date component to it, then assuming it is a time interval you could convert it to seconds or microseconds (lose the colons) and store it as a NUMBER.
If you want to maintain the exact formatting as shown, your only option is to store it as text using VARCHAR2 or something similar.
I have tried to insert date into the postgresql in 'dd.mm.yyyy' format.
First inserted the string type, then the date type
moment(new Date()).format('DD.MM.YYYY') but in database format always like 'yyyy-mm-dd'
What can I do?
Plesase, help
I stored date in database but whenever i am fetching then its format change
getting date - 2018-07-31T06:48:01.649Z
stored date in db - 2018-07-31 12:18:01.649
here is my code
var timee = result.created;
By default, dates are stored in UTC in MongoDB so you are seeing the difference in the time zone of stored and retrieved dates.
new Date() returns the current date as a Date object. The mongo shell wraps the Date object with the ISODate helper. The ISODate is in UTC.
You can read the MongoDB specification here.
There are several approaches that you can apply. Either convert the date to UTC timezone before saving it or convert into locale time zone after loading the date.
new Date(ISODate().toString() + 'UTC')
ISODate("2018-08-01T11:39:39Z")
and to replace the T and Z with an empty space using the javascript.
dateString.replace("T", " ").replace("Z", " ");
I'm referring to one of the presentation slide from eBay - http://www.slideshare.net/jaykumarpatel/cassandra-data-modeling-best-practices
I want to try out the same thing. Hence, I create the following table.
CREATE TABLE ebay_event (
date text,
eventtype text,
time timeuuid,
payload text,
PRIMARY KEY((date, eventtype), time));
Then, in my PHP script, I will perform insert using the following insert statement.
insert into ebay_event(date, eventtype, time, payload) values('03031611', 'view', now(), 'additional data');
Instead of hard code value '03031611', is there a way to tell cassandra, to generate ddmmyyhh based on the now() value of timeuuid column?
No. There are no such functions available in cassandra. You will have to create it in the language you are using.
Values for the timestamp type are encoded as 64-bit signed integers
representing a number of milliseconds since the standard base time
known as the epoch: January 1 1970 at 00:00:00 GMT.
There are some functions available that can create date in YYYY-mm-dd format.
Date from timeuuid