You need to sign in to do that
Don't have an account?
Date/DateTime operations
Is there a simpler way to deal with dates and times in apex other than calculating based on milliseconds? I've found the date/datetime operations to be quite gimped in Apex. I appreciate the ability to add days, seconds etc.. Where are the subtract and comparison methods? I'm coming from a C# background, bare with me here.
I have various things i need to accomplish, some are very straightforward.. Others are not.
Checking whether a date/datetime is:
- Before another date/datetime
- Less/more than N days before a date/datetime
- Is before a certain time (and how to get the delta between the two, IE in the form of a TimeSpan or equivalent..)
Please any help would be appreciated, i do not have any code examples to provide. I am hoping for an elegant solution that will not steer me even further away from salesforce.
Thanks
someDateTIme.addHours(-10);
There's no supplied equivalent of TimeSpan, for comparing dateTimes, you can use < and >
All Answers
there's addHour etc, see the docs
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_datetime.htm
Thanks for the response, however i've seen this documentation. I'm sort of looking the same set of functions only instead of add, subtract? It's apparent they probably do not exist in the apex framework but i'm sure the community has faced similar situations. I hope someone has some insight on how to more easily compare the dates and times. Most important to me is finding the delta between two dates other than in the form of milliseconds.
-Kyle
someDateTIme.addHours(-10);
There's no supplied equivalent of TimeSpan, for comparing dateTimes, you can use < and >
Thanks, the ms delta will have to suffice.