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
GunnarGunnar 

Fun with dates ! :-)

 

Batch inserting records. Have a problem with dates.

Salesforce assigns something different.

 

// run the following two lines in the immediate window of the developer console.

Date TodaysDate = date.today();
system.debug(TodaysDate);

 

You will get this ...

12:39:07:022 USER_DEBUG [2]|DEBUG|2013-07-01 00:00:00

 

Perfect!

 

Now, I'm creating the record and the following is one of the lines in the create object code.

    Received_Date_Time__c = todaysDate.addDays(-d)

 

Received_Date_Time__c is a date/time field.

 

When I look at the object.Received_Date_Time__c, the value is 6/30/2013 5:00 PM

 

I need the value from the debug - 2013-07-01 00:00:00 to appear in the field.

 

6/30/2013 <> 2013-07-01.

 

For laughs, I created another field, this being a 'DATE' field, and it does record the 2013-07-01. However, we cannot change the Received_Date_Time__c to a DATE field.

 

Any ideas on how to get 2013/07/01 into the DateTime field?

 

thanks in advance.

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

Its not Fun at all!

This is how salesforce handles date!

 

Salesforce actually saves the record in GMT! So when you are seeing through the Debug its actually showing the GMT time.

But when you are looking at the record using the Standard UI/Pagelayouts the datetime are adjusted based on current user's timezone.

 

 

All Answers

Avidev9Avidev9

Its not Fun at all!

This is how salesforce handles date!

 

Salesforce actually saves the record in GMT! So when you are seeing through the Debug its actually showing the GMT time.

But when you are looking at the record using the Standard UI/Pagelayouts the datetime are adjusted based on current user's timezone.

 

 

This was selected as the best answer
GunnarGunnar

Fixed it with this code change ...

 

       // Date        TodaysDate = date.today();
        DateTime    TodaysDate = datetime.now()

 

But I must remember!   Tomorrow is today!