Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am trying to get the smallest possible value for date (ie, the earliest date). If I were using Java, I would do something like this:

new Date(Long.MIN_VALUE)

source

I could do something like this, but that seems like a lot of extra work. I could also just hard code the value like this: datetime.newInstance(-99999999999L);, because I think that is the smallest Long value possible... But that is not the nicest thing.

Any better ideas?

share|improve this question
    
Why are you trying to get the earliest possible date? –  Daniel Hoechst Feb 14 '13 at 6:11
    
@DanielHoechst, two reasons: 1. I want a default date when searching (when there is no input), and 2. Because I want to know :) –  lindon fox Feb 14 '13 at 6:14

1 Answer 1

up vote 3 down vote accepted

I question the validity of what you're doing, since I've never seen this to be necessary, but since you asked, from the docs:

The earliest valid date is 1700-01-01T00:00:00Z GMT, or just after midnight on January 1, 1700. The latest valid date is 4000-12-31T00:00:00Z GMT, or just after midnight on December 31, 4000.

So therefore to construct the earliest possible date, you'd do something like

Date myDate = date.newinstance(1700, 1, 1);

(Untested but it should work. Also, probably irrelevant but your Java example is constructing a very late date, not a very early date.)

share|improve this answer
    
Thanks for the answer. It is similar to my hard coded example (min value of Long). I was hoping there would be a better answer than a hard coded value (in the max case to avoid the dreaded Y4K bug - you may be laughing now...). But it does seem like there is no nice way to get it. Thanks for the note too about the java example, I have modified my question. I would like to leave this question open for some time in case anyone has a better answer. But I will mark this as the answer if nobody has anything better. Cheers –  lindon fox Feb 14 '13 at 6:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.