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
ramkramk 

how to convert date time value into seconds in salesforce

Hi

 i have a date time value Datetime dt = DateTime.parse( '10/14/2011 11:46 AM');

 

now can i convert this into total seconds for that date value???

Devendra@SFDCDevendra@SFDC

Hi,

You can make use of getTime() method of DateTime.

getTime() - Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this DateTime object.

DateTime dt = System.Now();
Long i = dt.getTime();
System.debug('i=====>'+i);

After receivinng milliseconds value, you can convert that value into seconds.

Thanks,
Devendra

Abhi_TripathiAbhi_Tripathi

hey,

i think you should change the format and use a formula to change current time into seconds.

 hope this thing works

 

Cheers

Abhi

 

ManjunathManjunath

Hi,

 

You have created the datetime, you can extract hrs, minute, from it and multiply with respective seconds. Sum them up you will get total seconds.

 

Ex :  11:30 AM

11*3600=39600

30*60=1800

 

DateTime class has methods to extract minutes and hrs.

 

Regards