I am trying to script an import which involves setting some date fields with imported data stored as strings in a text file. The stored strings are in the format ‘Wed Jan 12 2005 10:58:54 GMT-0000 (GMT)’. I need to convert the strings into dates before putting them into the date fields. The best option for this seems to be the .parse function but I cannot get it work.
If I have a text string as above, how do I use the parse function to convert it to a valid date?
If I enter
var datestr = 'Wed Jan 12 2005 10:58:54 GMT-0000 (GMT)'
var mydate = new Date();
mydate.setTime(datestr.parse())
I simply get a ‘parse is not a function’ error.
Similarly
var datestr = 'Wed Jan 12 2005 10:58:54 GMT-0000 (GMT)'
var mydate = new Date()
mydate.parse(datestr)
returns the same error. I’m sure I’m just getting the syntax or data types wrong somewhere
I have a similar problem. I am writing records to a text file, using a generic method that writes whatever field of whatever field type. Then I need to re-import that record and run into this problem:
When I do something like
record.date_field
I get for example
Mon Jul 25 16:25:12 CEST 2005
When I then use the example above
var aDate = new Date(‘Mon Jul 25 16:25:12 CEST 2005’)
I get an invalid date.
When instead of step 1 I do
new Date(record.date_field)
I receive
Mon Jul 25 2005 16:25:12 GMT+0200 (CEST)
which can be perfectly used in step 2.
So it looks that the return type of a (date) dataprovider is somewhat different from a typical Java date type.
Can this be confirmed? Is there a solution for my problem that I currently don’t see?