function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mike @ BlackTabMike @ BlackTab 

Parsing Dates From Text

I have text from a textbox in this date format: 'mm/dd/yyyy' and use the following method to parse it:

 

date mydate = date.parse('12/27/2009');

 However when I try to insert the field into the database I get an Invalid Date Format error

 

What am I missing here?

sornasorna

Not sure what you are missing here...before inserting into database, add a debug statement to see if the date is valid...

Or you can also the function date.valueOf(string)

string year = '2008';
string month = '10';
string day = '5';
string hour = '12';
string minute = '20';
string second = '20';
string stringDate = year + '-' + month
+ '-' + day + ' ' + hour + ':' +
minute + ':' + second;
Date myDate = date.valueOf(stringDate);

 

For hour, minute & second, use '00' as values.