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
kittu9kittu9 

Difference between two dates

I have one date field tht is returning date as '2013-06-03'. I want to subtract this date with todays date.

 

Whn am trying for today's date using Date d = Date.today(); It is returing time also along with date. I want only date part. How to retrive only date part

 

1) datetime myDateTime = datetime.now();
Date d = myDateTime.date();

 

 

2) date tt = system.today();

string ss = tt.format();

 

Tried in differenct scenarios but getting time also can any one help me on this. Only wanto get the date part.

 

Joining_Date__c - Today () >= 25

 

This is the condition for me. Want to do this

Sean TanSean Tan

As far as I know System / Date.today() does not include any timestamp, the Date object doesn't even have any time fields on it.

 

I've tried this block of code and it worked fine for date compares.

 

Date today = System.today();
System.debug('Printed Date:::' + today.format());

Date pastDate = System.today().addDays(-50);

if (pastDate.daysBetween(today) >= 50)
{
System.debug('Number Of Days Between::: ' + pastDate.daysBetween(today));
}

 This is what gets spit out in my debug log:

 

08:23:05.038 (38242000)|USER_DEBUG|[2]|DEBUG|Printed Date:::07/06/2013
08:23:05.038 (38386000)|USER_DEBUG|[8]|DEBUG|Number Of Days Between::: 50

 

 

Avidev9Avidev9

Did you try this ?

 

integer numberDaysDue =  Obj.Joining_Date__c.daysBetween(system.today());