This is a strange issue. In my mongodb, I have ISODate something like this:
ISODate("1937-08-03T00:00:00.000Z")
in my find, I am doing
var isoString = new Date(inputDate).toISOString();
db.collection.find({dob: new Date(isoString)})
'inputDate' cab be yyyy-MM-dd or MM/dd/yyyy
when I convert string that is user inputted '1937-08-03' using Date().toISOString(), so I get
1937-08-03T00:00:00.000Z
but when my date format changes to 08/03/1937, using Date().toISOString(), I see ISO string as
1937-08-03T04:00:00.000Z
if you notice, I see 4 hours added when my date format changed to MM/dd/yyyy from yyyy-MM-dd. so obviously with extra 4 hours added, I am not able to pull the record from the db (no match)
How do I work this?
I am using Node and mongo. Thanks for any help.
OK here is how I handled the work around. I know my input date formats are either MM/dd/yyyy or MM-dd-yyyy so I split the string based on / OR - using the regex, and then reformatted back to yyyy-mm-dd format which works fine. If anyone has better solution, please post it here.
var dtArray = inputDate.split(/-|\//);
var dtStr = dtArray[2]+'-'+dtArray[0]+'-'+dtArray[1];
Related
I need to convert timestamp digits to string, for example, 15126..., into string format, I need it still look like digits 15126..., but in string format, not in any date or time format.
I tried intValue, just got error. All I found else is converting timestamp to date format like 2015-05... or vice versa, didn't find a scenario like mine. Would appreciate if anyone can help me.
Thanks.
By Timestamp, I'm assuming you mean java.sql.Timestamp.
Easiest way I can think of to do what you're asking is
Timestamp time = new Timestamp(System.currentTimeMillis())
long seconds = time.toInstant().getEpochSecond()
println seconds
This is a 2 question post:
When I enter a date for a document into MongoDB through an html form, I'll enter it using this format: YYYY-MM-DD
For example: 2014-02-13
However, in MongoDB, it inputs it in the ISOdate format, and while the YYYY-MM-DD will be correct, for whatever reason it will insert one of 3 different hour time stamps:
ISODate("2016-02-02T00:00:00.000Z")
ISODate("2015-02-16T05:00:00.000Z")
ISODate("2016-08-02T04:00:00.000Z")
I never specify the hour when entering dates, but for whatever reason it will always insert into MongoDB an hour of 0, 4, or 5.
I have no idea why it's doing this.
Alternatively, is there a way to remove the 'time' part of the date, seeing as I don't need it? For 'date' all I need is YYYY-MM-DD.
To return only the date as a date object you can try this:
var myDate = new Date("2016-05-18T16:00:00Z");
When uploading an Excel file in Web Dynpro for ABAP with date, the date looks like 41851 instead of 7/31/2014.
How can I solve this problem?
Excel stores Dates as numbers. To display that number as Date as you know it, format the cell as Date cell.
Use this formula =TEXT(41851,"YYYY-mm-dd") and the date should upload correctly (you can change the format string to whatever you need).
I found solution:
data: lv_data type sy-datum,
lv_startdate type sy-datum.
lv_startdate = '19000101'. "starting date(excel parameter)
lv_data = lv_startdate + 41851(the date from excel that we need to convert to normal date) - 2.
write lv_data.
this code works, thx all for help.
I have an excel file, with a date column, but I want to convert the date column to
YY/MM/DD/Time
Ive been searching for 2 hours and no result yet.
This is my data:
Source Data: http://i.stack.imgur.com/75zbS.jpg
Expected Output: YY/MM/DD/Time
Can someone help me how I can do it? I want to insert it into postgresql and I want to change everything to compatible date format.
EDIT: I have tried Right Click -> Format cells -> date but it does not change anything!
Thanks
You could use this method and split the date and time into separate cells:
=DATE((LEFT(A1,4)),(MID(A1,5,2)),MID(A1,7,2))
=TIME(MID(A1,10,2),(MID(A1,12,2)),0)
Once your date value is in a format Excel can recognize, you can then change the formatting to whatever you'd like.
Or if you don't care to have the value in a recognizable date format, you can just get your desired formatting like this (will give you a string that looks like this: YY/MM/DD/Time):
=MID(A1,3,2)&"/"&MID(A1,5,2)&"/"&MID(A1,7,2)&"/"&MID(A1,10,4)
ISO 8601 format would be YYYY-MM-DD H24:MI:SS.
But you can set Postgres to accept various date styles by setting the datestyle setting. You can do that globally in postgresql.conf or temporarily for your session.
SET datestyle = SQL, DMY
For more exotic formats, you can create a temporary staging table, COPY to it and INSERT into your target table from there. Among others, you can use to_timestamp():
SELECT to_timestamp('13/10/14/17:33', 'YY/MM/DD/hh24:mi')
More info and example code in related answers like these:
Replacing whitespace with sed in a CSV (to use w/ postgres copy command)
How to bulk insert only new rows in PostreSQL
Your going to have to parse the date into four columns using fixed parsing.
Then reassemble the columns any way you want.
Just Google with excel parse columns fixed.
In MongoDB I've stored dates prior to B.C has String type. How can I stored in ISODate() type ?
I've tried this :
db.test.insert({"date" : new ISODate("-63-09-23") })
but I get an error :
uncaught exception: invalid ISO date
Thanks for your help !
The MongoDB IsoDate() is just a wrapper around the normal javascript Date, which can take dates to 100 million days before 1970, so something like setFullYear() is probably what you need - like this: Can you create dates that are lower than 271800 BC? Like dinosaur time?
As Nik pointed out MongoDB dates are just javascript Dates. So you need to transform an ISODate back and forth to the underlying javascript Date. If you don't need to do queries based on the date you can also optionally store the date as a string instead.