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

How to find number of days as a result for record created date from today() ?

I need to find number of days old the record was created. Example - Record 1 was created on 01/Jan/2015. 

How can use the below code in my vf page? 
Date startDate = Date.newInstance(2008, 1, 1);
Date dueDate = Date.newInstance(2008, 1, 30);
Integer numberDaysDue = startDate.daysBetween(dueDate);

Something else tricky to get the number back as a result? Further I need to show that in a table. 
Akhil AnilAkhil Anil

You can use the below snippet to count the number of days from creation date to today.
Integer days = custobj.CreatedDate.Date().daysBetween(date.Today());

You cannot directly find this value in your VF page. Place the above code in your controller and then you can display the "days" variable in your VF page.

Kindly mark it as an answer if that solves your purpose
Vishal Negandhi 16Vishal Negandhi 16
Akhil is correct. 

So make this variable as a public variable in your class. 

public Integer numberDaysDue {get;set;}

and now if you add your code:
Date startDate = Date.newInstance(2008, 1, 1);
Date dueDate = Date.newInstance(2008, 1, 30);
numberDaysDue = startDate.daysBetween(dueDate);

Now your variable will display the correct number on VF page too.

Hope this helps :)