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
Smurfet15Smurfet15 

Date format issue, removing the time 00:00:00

Hi guro,

I have a requirement display: Contract Date - 25/01/2015 to 24/01/2016

my code : contact_date = 'Contract Date'  + '  - ' + string.valueOfGmt(s_date) + ' to ' + string.valueOfGmt(e_date);
Resulted to : Contract Date - 25/01/2015 00:00:00 to 24/01/2016 00:00:00

Tried this : contact_date = 'Contract Date'  + '  - ' + s_date.format('dd/MM/yyyy')  + ' to ' + s_date.format('dd/MM/yyyy')
but resulted to different date.

first code is fine but need to remove the time 00:00:00.

Thank,
Smurfet
KevinPKevinP
You're trying to Date.Format a dateTime variable. try calling s_date.date();
Arunkumar RArunkumar R
You can try out the below one,
 
contact_date = 'Contract Date' + ' - ' + (s_date.day() +'/'+s_date.month()+'/'+s_date.year()) + ' - '+ (e_date.day() +'/'+e_date.month()+'/'+e_date.year());
System.debug('## contact date'+contact_date);

 
Smurfet15Smurfet15
Hi Arunkumar,

This resulted to different date.

Hi Kevin,

This resulted to :  25/01/2015 00:00:00

Thanks for your help but still have the same issue.

Please shoot some answer of you know. 

Thanks again Smurfet.
 
Arunkumar RArunkumar R
Hi smurfet,

The above example code will exactly return what you want i.e "Contract Date - 25/01/2015 to 24/01/2016".

Could you share some additional info/code to debug?
Smurfet15Smurfet15
Hi Arunkumar,

Please take a look below:
Code:
   datetime s_date =  olitemUp.Maintenance_start_date__c;
   datetime e_date =  olitemUp.Maintenance_end_date__c;
   contact_date1 = ' - ' + string.valueOfGmt(s_date) + ' to ' + string.valueOfGmt(e_date);
   contact_date = 'Contract Date' + ' - ' + (s_date.day() +'/'+s_date.month()+'/'+s_date.year()) + ' - '+                    (e_date.day()+'/'+e_date.month()+'/'+e_date.year());
     system.debug('#contact_date1 : ' + contact_date1); 
      system.debug('#contact_date : ' + contact_date); 

 Debug----
12:41:07.907 (1907608200)|USER_DEBUG|[44]|DEBUG|#contact_date1 : - 2015-10-25 00:00:00 to 2015-10-30 00:00:00
12:41:07.907 (1907659194)|USER_DEBUG|[45]|DEBUG|#contact_date : Contract Date - 24/10/2015 - 29/10/2015

thanks,
Mary