Page 1 of 1

Inserting yesterday's date - more specific date functions.

Posted: Sat Dec 20, 2003 2:22 pm
by jasonb
Currently, it looks like there are only very basic date functions.

I doubt that it's possible, but is there any way of somehow getting yesterday's date to be inserted?

I'm trying to work with long dates, but I've customized my system preferences to not include the weekday name. (So, as I type this, today would be expressed as "December 20th, 2003".

If this can't be done natively, can anybody think of some kind of regex that would be able to do this? (It would have to be fairly complex, because it would have to deal not only with decrementing the day of the month by one, but also (potentially) changing the month name, day of the month suffix, and the year.)

Posted: Sat Dec 20, 2003 7:32 pm
by CyberSlug
See the AutoIt program I mentioned in your other post :)
EDIT: Revised code again. Hope it's bug free!

Code: Select all

; AutoIt script to insert yesterday's date
; 
;; MONTHS--full names
$month = StringSplit("January,February,March,April,May,June,July,August,September,October,November,December", ",")

;; COUNT--number of days per month
$c = StringSplit("31,0,31,30,31,30,31,31,,30,31,30,31", ",")
$c[2]  = daysInFeb(@year)

;; DAYS--ordinals with suffix
Dim $day[32]  ;index 0 to 31
For $i = 1 to 31
	$onesDigit = mod($i,10) 
	Select
		Case $onesDigit = 1
			$day[$i] = $i & "st"
		Case $onesDigit = 2
			$day[$i] = $i & "nd"
		Case $onesDigit = 3
			$day[$i] = $i & "rd"
		Case Else
			$day[$i] = $i & "th"
	EndSelect
Next

;; TODAY's DATE
$d = Int(@MDAY)  ;day, value 1 to 31
$m = Int(@MON)   ;month, value 1 to 12
$y = Int(@YEAR)  ;year, four-digit year


;; CALCUALTE YESTERDAY'S DATE
If $d = 1 And $m = 1 Then  ;treat Jan 1st as special case
	$d = 31
	$m = 12  ;December
	$y = $y - 1
Else
	If $d - 1 = 0 Then  ;today is first day of new month
		$m = $m - 1      ;yesterday was last month
		$d = $c[$d]
	Else
		$d = $d - 1	 ;simply decrement day
	EndIf
EndIf


; Paste date into program
$bak = ClipGet()
ClipPut($m & $month[$m] & " " & $d & $day[$d] & ", " & $y)
WinMenuSelectItem("TextPad", "", "&Edit", "&Paste")
ClipPut($bak)

Exit


Func daysInFeb($y)  ; return number of days in February
	If mod($y, 4) = 0 Or (mod($y, 100) <> 0 And mod($y, 400) = 0) Then
		Return 29  ;leap year
	Else
		Return 28
	EndIf
EndFunc
8) 8)

Posted: Sun Dec 21, 2003 2:59 pm
by jasonb
Thanks, I'll look into it.