gcriaco Posted May 19, 2004 Posted May 19, 2004 ;==================================================== ; ; Description: Returns the previous day's date ; Syntax: _DateLastDay( $DateIn, $Delimiter ) ; Parameter(s): $DateIn - Input date ; $Delimiter - Delimiter of Days, Month and Year ; Requirement(s): Date is in format DD/MM/YYYY, where "/" is a variable delimiter ; You need to include Date.au3 (#include <Date.au3>) ; Return Value(s): On Success - Returns the previous day's date ; On Failure - Returns 0 and sets @error = 1 ; Author(s): Giuseppe Criaco <gcriaco@quipo.it> ; ;==================================================== Func _DateLastDay($DateIn, $Delimiter) $ArrDate = StringSplit($DateIn, $Delimiter) $DD = $ArrDate[1] $MM = $ArrDate[2] $YYYY = $ArrDate[3] If $ArrDate[0] <> 3 Then SetError( 1 ) Return 0 Exit EndIf If _DateIsValidMonthNum( $MM ) And _DateIsValidYear( $YYYY ) Then If $DD > 1 Then ;Day > 1 $DD = $DD - 1 ElseIf $MM > 1 Then ;Month > 1 $MM = $MM -1 Select Case $MM = 02 If _DateIsLeapYear( $YYYY ) = 1 Then $DD = 29 Else $DD = 28 Endif Case $MM = 04 OR $MM = 06 OR $MM = 09 OR $MM = 11 $DD = 30 Case Else $DD = 31 EndSelect Else $DD = 31 $MM = 12 $YYYY = $YYYY -1 EndIf Else SetError( 1 ) Return 0 Exit EndIf $DD = StringFormat( "%02d", $DD ) $MM = StringFormat( "%02d", $MM ) $DateOut = $DD & $Delimiter & $MM & $Delimiter & $YYYY Return $DateOut EndFunc
sykes Posted May 20, 2004 Posted May 20, 2004 Can't seem to get this one to do anything ... Am I leaving something out here?? We have enough youth. How about a fountain of SMART?
rogerd2u Posted May 20, 2004 Posted May 20, 2004 Me either...what am I missing here?? Roger O."When people show you who they are, believe them. --Mark Twain
Developers Jos Posted May 20, 2004 Developers Posted May 20, 2004 How did you use it ??? this seems to work fine: expandcollapse popup#include <date.au3> msgbox(0, 'test',_DateLastDay(@MDAY & "/" & @MON & "/" &@YEAR ,"/")) exit ;==================================================== ; ; Description: Returns the previous day's date ; Syntax: _DateLastDay( $DateIn, $Delimiter ) ; Parameter(s): $DateIn - Input date ; $Delimiter - Delimiter of Days, Month and Year ; Requirement(s): Date is in format DD/MM/YYYY, where "/" is a variable delimiter ; You need to include Date.au3 (#include <Date.au3>) ; Return Value(s): On Success - Returns the previous day's date ; On Failure - Returns 0 and sets @error = 1 ; Author(s): Giuseppe Criaco <gcriaco@quipo.it> ; ;==================================================== Func _DateLastDay($DATEIN, $DELIMITER) $ARRDATE = StringSplit($DATEIN, $DELIMITER) $DD = $ARRDATE[1] $MM = $ARRDATE[2] $YYYY = $ARRDATE[3] If $ARRDATE[0] <> 3 Then SetError(1) Return 0 Exit EndIf If _DateIsValidMonthNum ($MM) And _DateIsValidYear ($YYYY) Then If $DD > 1 Then;Day > 1 $DD = $DD - 1 ElseIf $MM > 1 Then;Month > 1 $MM = $MM - 1 Select Case $MM = 02 If _DateIsLeapYear($YYYY) = 1 Then $DD = 29 Else $DD = 28 EndIf Case $MM = 04 Or $MM = 06 Or $MM = 09 Or $MM = 11 $DD = 30 Case Else $DD = 31 EndSelect Else $DD = 31 $MM = 12 $YYYY = $YYYY - 1 EndIf Else SetError(1) Return 0 Exit EndIf $DD = StringFormat( "%02d", $DD) $MM = StringFormat( "%02d", $MM) $DATEOUT = $DD & $DELIMITER & $MM & $DELIMITER & $YYYY Return $DATEOUT EndFunc ;==>_DateLastDay SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
rogerd2u Posted May 20, 2004 Posted May 20, 2004 OK, that works. Stupid question: How do I get it to format the date as MM/DD/YYYY ?? :-) Roger O."When people show you who they are, believe them. --Mark Twain
Developers Jos Posted May 20, 2004 Developers Posted May 20, 2004 (edited) OK, that works. Stupid question: How do I get it to format the date as MM/DD/YYYY ?? :-)EDIT: just change this portion: $MM = $ARRDATE[1] $DD = $ARRDATE[2] $YYYY = $ARRDATE[3] Edited May 20, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
sykes Posted May 21, 2004 Posted May 21, 2004 OK works great now ... was trying to get the value from $DateOut but it was saying the variable had not been defined You can also change the output format here: $DATEOUT = $DD & $DELIMITER & $MM & $DELIMITER & $YYYY I needed it to show date in the following fomat: $DATEOUT = $YYYY & $MM & $DD So it shows as 20040520 (without delimiters) Very nice UDF though ... I'll definetely be using this one We have enough youth. How about a fountain of SMART?
Guest jj03 Posted October 1, 2004 Posted October 1, 2004 Here's a simpler version for calculating yesterday's date: #include <date.au3> $YYYY = @YEAR $MM = @MON $DD = @MDAY If $DD > 1 Then $DD = $DD - 1 ElseIf $MM > 1 Then $MM = $MM - 1 $DD = _DateDaysInMonth ($MM, $YYYY) Else $DD = 31 $MM = 12 $YYYY = $YYYY - 1 EndIf $YesterdayDate = StringFormat("%02d/%02d/%04d", $DD, $MM, $YYYY)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now