Jump to content

Need help with formatted Date output


Recommended Posts

I'm trying to output the date in the format "Thu Aug 29". There are many date functions but no single function seems to be able to do this(unless I overlooked it).

I want to store this formatted date into a variable and then subtract 1 day and store into another variable so I need to be careful that the code "knows" that if today is Mon Sep 1, that yesterday was Sun Aug 31.

Thanks - CA

Link to comment
Share on other sites

I'm trying to output the date in the format "Thu Aug 29". There are many date functions but no single function seems to be able to do this(unless I overlooked it).

I want to store this formatted date into a variable and then subtract 1 day and store into another variable so I need to be careful that the code "knows" that if today is Mon Sep 1, that yesterday was Sun Aug 31.

Thanks - CA

Dim $Days[7] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
Dim $Month[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
$CurentDate = $Days[@WDAY - 1] & " " & $Month[@MON - 1] & " " & @MDAY
MsgBox(0, "", $CurentDate)

;)

Link to comment
Share on other sites

Doh noticed you wanted to subtract a day.

Here it is:

#Include <Date.au3>


Dim $Days[7] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
Dim $Month[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]


$Split = StringSplit(_DateAdd('d', -1, _NowCalcDate()), "/")
$CurentDate = $Days[_DateToDayOfWeekISO($Split[1], $Split[2], $Split[3])] & " " & $Month[$Split[2] - 1] & " " & $Split[3]

MsgBox(0, "",    $CurentDate )
Edited by Szhlopp
Link to comment
Share on other sites

Thanks - this looks like it will work. I was hoping there was a UDF that would output in any format but guess not. Thanks again.

CA

Np,

Also, you can easily change how it outputs...

$CurentDate =

$Days[_DateToDayOfWeekISO($Split[1], $Split[2], $Split[3])] - The day

& " " &

$Month[$Split[2] - 1] - The month

& " " &

$Split[3] - The date (28th)

=)

Link to comment
Share on other sites

Perhaps my original question was not clear.

I need to store today's date into a variable in the format "Wed Aug 29"

I need to subtract 1 day from today's date to get yesterday's date

I need to store yesterday's date into a variable in the same format "Wed Aug 28"

Subtracting 1 from @WDAY won't work because if it happens to be be Sunday(0) subtracting 1 will go negative

Here's what I had so far in the original post

$tTime = _Date_Time_GetSystemTime()

$aTime = _Date_Time_SystemTimeToArray($tTime)


$sShortDayName = _DateDayOfWeek( $aTime[7], 1 );element 7 contains the day of the week as an integer

$sShortMonthName = _DateToMonth($aTime[0], 1)  ;element 0 contains the month of the year as a number

$Today = $sShortDayName & " " & $sShortMonthName & " " & @MDAY ; "Fri Aug 29"

;Can I do something along the following lines to create yesterday?

$sNewDate = _DateAdd('D',-1, $tTime) ; subtract 1 day from today's date

;What would go here??

Thanks - CA

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...