Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date comparisons

Status
Not open for further replies.

cleavitt

Programmer
Joined
Jun 25, 2002
Messages
3
Location
CA
Is there some way of comparing 2 dates in vbscript to tell which one comes first?

Any tips would be greatly appreciated!
 
Once they are in Variant(Date) format then you just use normal IF statements. Use DATExxxx functions to convert various data types to Dates. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
<script language=&quot;VBscript&quot;>
Dim one, two
one = DateValue(#10/5/97#)
two = DateValue(#10/7/98#)
if Year(one)>Year(two) then
myVar = msgbox(&quot;one is before two&quot;)
elseif day(one)>day(two) then
myVar = msgbox(&quot;one is before two&quot;)
else
myVar = msgbox(&quot;two is before one&quot;)
end if
</script> I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Onpt,
What is wrong with If date1 < date 2 then

your example leaves out month entirely and does not deal with <= for Year or Day.

Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
JohnYingling
it was just a example of a way I determined a while ago which date was teh earliest per year value. I guess I just assumed the year thing would be changed to satify the needs here. [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top