+ Start a Discussion
SurenderSurender 

Remove the timestamp from the DateField Value

Hi,

 

Can someone guide us like how can we remove the timestamp from the DateField Value.

 

Ex: Suppose i have Date value like 2011-11-15 00:00:00 then i want to print only 2011-11-15.

 

Please share your thoughts on this.

 

Regards

G. Surender

Best Answer chosen by Admin (Salesforce Developers) 
raseshtcsraseshtcs

Datetime dateTimetemp = System.now();
System.debug('Before Date String'+dateTimetemp);
Date dateTemp = Date.newInstance(dateTimetemp.year(),dateTimetemp.month(),dateTimetemp.day());
System.debug('After Date String'+dateTemp);
String x=dateTemp.format();
system.debug('xxxx'+x);

 

Try this...

All Answers

raseshtcsraseshtcs

Try this

Datetime dateTimetemp = System.now();

Date dateTemp = Date.newInstance(dateTimetemp.year(),dateTimetemp.month(),dateTimetemp.day());

SurenderSurender

Hi,

 

I tried the above like

 

Datetime dateTimetemp = System.now();
System.debug('Before Date String'+dateTimetemp);
Date dateTemp = Date.newInstance(dateTimetemp.year(),dateTimetemp.month(),dateTimetemp.day());
System.debug('After Date String'+dateTemp);

 

Output:-

Before Date String2011-12-02 05:37:11
After Date String2011-12-01 00:00:00

 

 

In the output still am getting the timestamp values(as zeros), but i don't want to display them.

Can you please reply.

 

Regards

G. Surender

 

raseshtcsraseshtcs

Datetime dateTimetemp = System.now();
System.debug('Before Date String'+dateTimetemp);
Date dateTemp = Date.newInstance(dateTimetemp.year(),dateTimetemp.month(),dateTimetemp.day());
System.debug('After Date String'+dateTemp);
String x=dateTemp.format();
system.debug('xxxx'+x);

 

Try this...

This was selected as the best answer
SurenderSurender

Thanks it worked for me..

Manish Mahajan 9Manish Mahajan 9
Surender,
can you please tell what you did to get it work? I am still getting time with Zero's

Thanks