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
anurajanuraj 

Find date

Hi

Tell me how to get only date from a value or how to delete time from this format.

2011-09-20 00:00:00

 

thanks

Anuraj

pradyprady

If you have the value in a string then use

String s='2011-09-20 00:00:00';
string a=s.substring(0,10);
Date d=date.valueof(a);

 or

 

if its stored in a datetime field

date.valueof(a)

where a is a datetimefield

 

i havent tested them, these should work i guess

anurajanuraj

Hi

When it is in string type then it is 2011-09-20 format

afrer when it is converted to date then it comes in this format 2011-09-20 00:00:00. 

 

 

thanks

anuraj

ZedroidZedroid

Hi Anuraj

 

You can create a DateTime instance and then using string change the format like I did and got only the Date.

Try this.

 

// Create DateTime Instance

Datetime CurrentDateTime= system.now();

 system.debug('System.now :'+myDate1 );            

// Trim to get Date value

String myDat = CurrentDateTime.format('dd/MM/yyyy');

system.debug('After Concatenation :'+myDat );  


Regards,

Zubair


anurajanuraj

Hi Zubair

I am gettig this error

Compile Error: Method does not exist or incorrect signature: trim(Date)

thanks

Anuraj

ZedroidZedroid

Hi Anuraj,

 

You want to get the Date in DateFormat or StirngFormat?

 

Regards,

Zubair.

anurajanuraj

I want to get the date format but don't want time in it. 

I am getting 2011-09-20 00:00:00

I don't want time in it and want it as 2011-09-20

 

my code is 

  if (!StartDate.equals(''))
    
     myDate = date.valueOf(StartDate);
    soql += ' and  Start_Date__c = ' + myDate;

 

thanks 

Anuraj

Rahul SharmaRahul Sharma

This worked for me:

String s='12/27/2009 6:46 AM';
string a=s.substring(0,10);
Date d=date.parse(a); 
system.debug('======'+database.query('Select Id, Name from Account where Createddate > :d'));

 

VarunSforceVarunSforce

Try:

 

    soql += ' and  Start_Date__c = :myDate';