+ Start a Discussion
shan876shan876 

set date to 3 months out???

How do I in SOQL set lastmodifieddate to 3 months out???
lastmodifieddate
Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

You could use the Apex addMonths() function to do this in your controller. Here is a snippet:

 

public Account a { get;set;} public DateTime a3months {get;set;} public testController(){ //I am querying the account just as an example to get the lastmodified date a = [select id,lastmodifieddate from account limit 1] ; //Here I use the addMonths() to increment the date field plus 3 months. Then you can display this field to your VF page. a3months = a.lastmodifieddate; a3months.addMonths(3); }

 

 

 

All Answers

aalbertaalbert

LastModifiedDate field is read-only. The system maintains that field. You could create a custom field of Date or DateTime to default to 3 month out.

 

shan876shan876

Ohh I know that, just on my vf page I have to show the lastmodifieddate 3 months ahead of the dateitself... So I am changing it in the table...

So would you happen to know how to place it three months out on the VF page?

Thanks for replying so quickly..

aalbertaalbert

You could use the Apex addMonths() function to do this in your controller. Here is a snippet:

 

public Account a { get;set;} public DateTime a3months {get;set;} public testController(){ //I am querying the account just as an example to get the lastmodified date a = [select id,lastmodifieddate from account limit 1] ; //Here I use the addMonths() to increment the date field plus 3 months. Then you can display this field to your VF page. a3months = a.lastmodifieddate; a3months.addMonths(3); }

 

 

 

This was selected as the best answer
shan876shan876

Awesome so on my VF page would I say

<apex:outputText value="{!a3months}"/>???

aalbertaalbert

Correct. And if you want additional date formatting in the VF page itself, check out this posting on how to use MONTH(), YEAR(), DAY() formulas in VF.

 

shan876shan876

Thank you so much for helping me out it did work with the exception that it came out like this:

Mon Jun 08 23:15:16 GMT 2009

 

I tried

{0,{!a3months},MM/DD/YYYY} which change it to {0,6/8/2009,MM/DD/YYYY} ... How do I get rid of 0,...MM/DD/YYYY???

 

aalbertaalbert

Right, which is why I had a link to this posting to help you perform additional formatting. It shows how to use some simple Date formulas in the VF page to assist with formatting. 

 

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=10179

shan876shan876
I do not know why but leaving a space in there after the {!a3months} worked...????Boggles my mind