+ Start a Discussion
❤Code❤Code 

how to insert value into date data type field

Hi All,

I have a requirement where I am extracting date , month n year from a text field. I need to insert this value into a date data type field. How to do this..

Regards
Siddharth ManiSiddharth Mani
If all the values are in numbers then I gues this should work:
String date1 = '10';
String month = '2';
String year = '2016';
Date newDate = date.newinstance(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(date1));
system.debug(newDate);
If instead you have String value for month like 'March' etc. then you may have to write some code to change these into numbers and use the above. Or there might be a better way of doing it!!!
Dushyant SonwarDushyant Sonwar

Hi ,

It would be helpful if you can post in which format is your text field containing data.
From what i am assuming if your text field has data something like '23/12/2015' in string date form

then you can directly use below line something like this below:
 

Date newDate = Date.parse(yourtextfield);

Thank You
Dushyant Sonwar