Solved

compare datetime

Posted on 2012-03-20
3
1,089 Views
Last Modified: 2016-02-17
I need to do a datetime comparison that takes a string argument such as 9:00 AM and compares it to the current datetime on the server.  

So, if I wanted to compare 3/20/2012 9:00 AM > 3/20/2010 1:00PM it should be false because 9:00 AM is less than 1:00 PM.

One other issue is the time on the server is GMT and I need to translate that time into Mountain time (Phoenix, Arizona).

I'm posting in the java forum, but I'm writing this code in Apex (Salesforce language), which is a derivative of the Java language and is compiled on a Java App Server.  One issue is Apex does not have the Java class library available, so I have to write this from scratch.

Any help is appreciated.
Thank you.
0
Comment
Question by:-Dman100-
  • 2
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 37744119
>>> 3/20/2012 9:00 AM > 3/20/2010 1:00PM


that is true when you compare them as strings.
either reformat them to be sortable strings (yyyy/mm/dd HH:mi:ss - where HH is 24-hour clock)

or, convert the strings to datetime types
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 37744126
to convert a string to a date try something like this...


Datetime dt = DateTime.parse('3/20/2012 9:00 AM');
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37744148
Java has a lot of functionality associated with dates - if none of it is avaialable in Apex, it is not clear how you can do it
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Note: You must have administrative privileges in order to configure lead or case queues. Salesforce.com (http://www.Salesforce.com) is a cloud-based customer relationship management (CRM) system. It is widely used around the world by sales and ma…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now