DigDeep

Get Yesterday's date in mm/dd/yyyy

6 posts in this topic

I am able to get today's date in the MM/DD/YYYY format.

But I also want to get Yesterday's date in the same format. I tried using _DateADD but that gives me result in the M/DD/YYYY format.

Local $Today = _Date_Time_GetSystemTime()
Local $CalDate = _Date_Time_SystemTimeToDateStr($Today)

MsgBox(0, '', $CalDate)

Local $Yesterday = _DateTimeFormat(_DateAdd('d', -1, _NowCalcDate()), 2)

MsgBox(0, '', $Yesterday)

Can someone check once?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

.

Edited by Danp2
Nevermind

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes, I tried that too as stated above.

Local $Yesterday = _DateAdd('d', -1, _NowCalcDate())

But that gives me in the YYYY/MM/DD format. I wanted to get the result in the MM/DD/YYYY format.

I also tried to take the _DateAdd to convert it to my result as per below, but the code does not run.

Local $Yesterday = _DateAdd('d', -1, _NowCalcDate())
Local $Yesterday1 = $Yesterday[1] & "/" & $Yesterday[2] & "/" & $Yesterday[0]

MsgBox(0, '', $Yesterday)

 

Edited by DigDeep

Share this post


Link to post
Share on other sites

DigDeep,

#include "Date.au3"

Local $Today = _Date_Time_GetSystemTime()
Local $CalDate = _Date_Time_SystemTimeToDateStr($Today)

MsgBox(0, '', $CalDate)

Local $Yesterday = _DateTimeFormat(_DateAdd('d', -1, _NowCalcDate()), 2)
; Split DTG
$aYesterday = StringSplit($Yesterday, "/")
; Reassemble in desired order
$sYesterdayFormatted = $aYesterday[2] & "/" & $aYesterday[1] & "/" & $aYesterday[3]
MsgBox(0, '', $Yesterday & @CRLF & $sYesterdayFormatted)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks @Melba23.

I just modified it a little bit and got it.

;~ Local $Yesterday = _DateTimeFormat(_DateAdd('d', -1, _NowCalcDate()), 2)
Local $Yesterday = _DateAdd('d', -1, _NowCalcDate())
; Split DTG
$aYesterday = StringSplit($Yesterday, "/")
; Reassemble in desired order
$sYesterdayFormatted = $aYesterday[2] & "/" & $aYesterday[3] & "/" & $aYesterday[1]
MsgBox(0, '', $Yesterday & @CRLF & $sYesterdayFormatted)

 

Share this post


Link to post
Share on other sites

... have also a look to the _DateTimeSplit() function

#include <date.au3>

Local $aDatePart ; will receive the date splitted in [1] year, [2] month, [3] day
Local $aTimePart ; not used here

Local $Yesterday = _DateAdd('d', -1, _NowCalcDate())

Local $x = _DateTimeSplit($Yesterday, $aDatePart, $aTimePart)

Local $Yesterday1 = $aDatePart[2] & "/" & $aDatePart[3] & "/" & $aDatePart[1]

MsgBox(0, '', $Yesterday1)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
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