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
ismyhcismyhc 

Date showing 1 day behind for some reason when using date.format('yyyy-dd-MM')

I must be missing something..

 

The date is always 1 day behind when formating like so:

 

datetime xDate = o.campaign_start_date__c;
			
String xxDate = xDate.format('yyyy-dd-MM');
system.debug('sdate :' +xxDate);

 

I set the above field to 8/16/2011

 

and in debug it shows up as: 2011-15-08

 

Everytime I change it the debug value is shown as 1 day behind.. Im sure I could to +1, but could someone help me understand why this is happening?

 

Thanks!
Jacob Davis

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

This  is campaign_start_date__c  datetime field . And your users time zone must be such that GMT - some hours, so that GMT Offset makes a day less.

 

Try this

 

Datetime localTime = o.campaign_start_date__c.Date();
         
localTime = localTime.addHours(o.campaign_start_date__c.hour());
localTime = localTime.addMinutes(o.campaign_start_date__c.minute());
localTime = localTime.addSeconds(o.campaign_start_date__c.second());

String xxDate = xDate.format('yyyy-dd-MM');
system.debug('sdate :' +xxDate);

 

All Answers

Shashikant SharmaShashikant Sharma

This  is campaign_start_date__c  datetime field . And your users time zone must be such that GMT - some hours, so that GMT Offset makes a day less.

 

Try this

 

Datetime localTime = o.campaign_start_date__c.Date();
         
localTime = localTime.addHours(o.campaign_start_date__c.hour());
localTime = localTime.addMinutes(o.campaign_start_date__c.minute());
localTime = localTime.addSeconds(o.campaign_start_date__c.second());

String xxDate = xDate.format('yyyy-dd-MM');
system.debug('sdate :' +xxDate);

 

This was selected as the best answer
ismyhcismyhc

Thanks Shashikant!

 

Sorry, I forgot to follow up and let you know this worked for me. This was probably much better method that just adding a day to the current date.

 

Thanks!

Shashikant SharmaShashikant Sharma

Your welcome mate

Arshad NoorArshad Noor
You can visit our site on BloggingHIndi.com
Akash Deb NathAkash Deb Nath
Hey, its really amazing blog I am very much interested. Thanks for the great article. Regards, webmusic (https://www.godigitalzone.in/webmusic/)
Tension EndsTension Ends
Nice Information, 
I will try this on my website Gyani Guruji (https://gyaniguruji.in)
abhishek kumar 679abhishek kumar 679
was facing the same problem. Thank you so much. Tricksnhub (https://tricksnhub.com)
Rajat raiRajat rai
I was also have same doubt you can visit here https://allbestshayari.com/funny-shayari/
Rajat raiRajat rai
Hey i can think your problem can be solve from here http://allbesthashtag.com/best-birthday-hashtags/ (http://allbesthashtag.com/best-birthday-hashtags)
Satta King 6Satta King 6

https://sattakingnew.in/
https://sattakingnew.in/up-rajkot-satta.php
https://sattakingnew.in/black-satta-result.php
https://sattakingnew.in/online-satta-king.php
https://sattakingnew.in/desawar-gali-satta-king.php
Satta King 6Satta King 6

http://sattakingnew.in/
http://sattakingnew.in/up-rajkot-satta.php
http://sattakingnew.in/black-satta-result.php
http://sattakingnew.in/online-satta-king.php
http://sattakingnew.in/desawar-gali-satta-king.php
Daniel AltonDaniel Alton

Hey i think your answer can be solved by visiting here Powerdirector mod apk (https://freeapkhub.com/powerdirector-pro-apk/)

or from here tinder gold apk (https://freeapkhub.com/tinder-gold-apk/)

Daniel AltonDaniel Alton
Or you can also visit here Download Avg Cleaner Pro Apk (https://freeapkhub.com/latest-avg-cleaner-pro-apk/)
Daniel AltonDaniel Alton
If you want to see more about and you are not getting information then you can visit here Oreo Tv Apk (https://zapexploded.com/oreo-tv-apk/)
Rohit Sharma 426Rohit Sharma 426
Kuttyweb (https://rohitsharma.co/kuttyweb/) is a beloved and popular free streaming website that provides free movies and series online to everyone to watch for free of cost. Millions of users ...