Solved

compare datetime

Posted on 2012-03-20
3
1,124 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 92
custom annotations 9 39
Why my table column Id is not passed to java object? 4 39
Html Table Looping (part 2) 5 10
Note: You must have administrative privileges in order to create/edit Roles. Salesforce.com (http://www.salesforce.com/) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales and marke…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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 …

832 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