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
lady_syrennelady_syrenne 

getting the first 90 days of the year in apex ,, URGENT!

Hi all!

 

 

Does anyone know how to get the first 90 days of the year in apex? I'm new to dealing with dates in apex... Pls. help for this is very urgent!

 

 

Thanks,

 

lady

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

 

Use this;

 

Date myDate = date.newinstance(CALENDAR_YEAR(), 1, 1);
    for(Integer i = 0; i<91; i++)
    {
        System.Debug(myDate.addDays(i));
    }
    }

 For more: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_date_functions.htm

                   http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

Chamil MadusankaChamil Madusanka

Use following code

 

Date myDate = date.newinstance(1960, 2, 17);
    for(Integer i = 0; i<91; i++)
    {
        System.Debug(myDate.addDays(i));
    }
    }

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

lady_syrennelady_syrenne

This is good but can I do it dynamically? I think Date myDate = date.newinstance(1960, 2, 17) is sort of hardcoded date.. what if the year changes? can I do it without hardcoding dates?

Chamil MadusankaChamil Madusanka

 

Use this;

 

Date myDate = date.newinstance(CALENDAR_YEAR(), 1, 1);
    for(Integer i = 0; i<91; i++)
    {
        System.Debug(myDate.addDays(i));
    }
    }

 For more: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_date_functions.htm

                   http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
lady_syrennelady_syrenne

Great Thanks for this!