Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

compare datetime

Posted on 2012-03-20
3
Medium Priority
?
1,259 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 74

Accepted Solution

by:
sdstuber earned 2000 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 74

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

877 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