Jump to content

Recommended Posts

Posted

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?

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
  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

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)

 

Posted

... 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)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

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
  • Recently Browsing   0 members

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