Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

compare datetime

Posted on 2012-03-20
3
Medium Priority
?
1,225 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

719 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