CurrentDate More Than

Blitz3D Forums/Blitz3D Beginners Area/CurrentDate More Than

boomboom(Posted 2008) [#1]
Am I right in thinking that this:


If CurrentDate$() > "09 Jun 2008" End


Actualy works? I tested it and it does seem to end on any date after todays, I am just a little suprised that it does.

I am basically just trying to cut off my program so it can't run after a certain date.


boomboom(Posted 2008) [#2]
ok it seemed that it doesn't work, as I suspected, but it did work for todays date +- a few days, so I thought it did work. Coded up this function to do this, which I will also add to the codearcs.


;This Function converts the time from "09 Jun 2008" format to
;the "20080609" format, as an int. This will allow you to see
;whether one date is after another. This can be used to stop a
;program from running before or after a certain date:



;Stops program running after a certain date
If DateInt(CurrentDate()) >= DateInt("09 Jun 2008") End

;Stops Program running before certain date
;If DateInt(CurrentDate()) < DateInt("09 Jun 2008") End

;Program can only run on certain date
;If DateInt(CurrentDate()) <> DateInt("09 Jun 2008") End

Function DateInt%(Date$)

	;Local Variables -----
	Local D$
	Local M$
	Local Y$
	Local DateResult%
	;=====================

	;Get Day
	D = Left(Date,2)
	
	;Get Month
	Select Mid$(Date,4,3)
		Case "Jan" M = "01"
		Case "Feb" M = "02"
		Case "Mar" M = "03"
		Case "Apr" M = "04"
		Case "May" M = "05"
		Case "Jun" M = "06"
		Case "Jul" M = "07"
		Case "Aug" M = "08"
		Case "Sep" M = "09"
		Case "Oct" M = "10"
		Case "Nov" M = "11"
		Case "Dec" M = "12"
	End Select
	
	;Get Year
	Y = Right(Date,4)
	
	;Result Date
	DateResult = Int (Y + M + D)

	;Return Result Date
	Return DateResult

End Function




Yahfree(Posted 2008) [#3]
That won't work very well either...


for example..

Dec 31st 2008 would be greater than Jan 1st 2009?


boomboom(Posted 2008) [#4]
If you see I rearrange the date, so it goes YMD

So using your examples

Dec 31st 2008 = 20081231

Jan 1st 2009 = 20090101

So Jan 1st 2009 is bigger :)


Farflame(Posted 2008) [#5]
Errr, correct me if I'm wrong, but it won't give the answers you gave in your example above. 2008+12+31 = 2051, whereas 2009+1+1 = 2011? Unless it's a string?

I did something like this years ago, but just multiplied the year by 2000, the month by 100 and added the day.


boomboom(Posted 2008) [#6]
It is a string


GfK(Posted 2008) [#7]
There is code in the code archives to do this.