Jump to content

Help with DATE


Recommended Posts

Hi all

please can you help me. i am trying to get yesterdays date in day-month-year format. on every Monday. ie 08-07-2009

i use

$today   = @MDAY - 1 & "-" & @MON & "-" & @YEAR
MsgBox(0, "This Should be SUNDAY's Date", $today)

this works great until today's date is 1st to 9th of the month. then i get 8-07-2009 which won't work in my script.

what is worse is on the 1st of the month it doesn't get last month's date correctly.

i am playing with this script which i have got from the helpfile, but is is not working

#include <GuiConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
Local $aTime
; Add 5 days to today
;~ $tTime = _Date_Time_GetSystemTime()
$sNewDate = _DateAdd( 'd',-1, _Date_Time_GetSystemTime())
MsgBox( 4096, "", "Today - 1 days:" & $sNewDate )
    $aTime = _Date_Time_SystemTimeToArray($sNewDate)
MsgBox(0, "This Should be SUNDAY's Date", $aTime[1] & "-" & $aTime[0] & "-" & $aTime[2])

$today   = $aTime[1] & "-" & $aTime[0] & "-" & $aTime[2]
;$today   = "05-07-2009"
MsgBox(0, "This Should be SUNDAY's Date", $today)

HELP!

Link to comment
Share on other sites

How about

#Include <Date.au3>
MsgBox(0,"",_DateAdd("D",-1,@YEAR & "/" & @MON & "/" & @MDAY))
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Or

#Include <Date.au3>
 MsgBox(4096, "", "Yesterday's Date: " & StringRegExpReplace (_DateAdd('D', -1, _NowCalcDate()), "(\d{2,4}).(\d{2}).(\d{2})", "$3/$2/$1"))

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Or

#Include <Date.au3>
 MsgBox(4096, "", "Yesterday's Date: " & StringRegExpReplace (_DateAdd('D', -1, _NowCalcDate()), "(\d{2,4}).(\d{2}).(\d{2})", "$3/$2/$1"))

Mega

Thanks for the quick response. now i just need to put the date in the correct format. any suggestions? stringsplit perhaps?
Link to comment
Share on other sites

_DateTimeFormat could do what you need. It formats a date according to the PCs settings. Please have a look in the help file for the differen parameters for _DateTimeFormat.

#Include <Date.au3>
    MsgBox(0,"",_DateTimeFormat(_DateAdd("D",-1,_NowCalcDate()),0))

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

_DateTimeFormat could do what you need. It formats a date according to the PCs settings. Please have a look in the help file for the differen parameters for _DateTimeFormat.

#Include <Date.au3>
    MsgBox(0,"",_DateTimeFormat(_DateAdd("D",-1,_NowCalcDate()),0))

Thanks. that worked a treat :)
Link to comment
Share on other sites

Hi,

you can change it in the RegEx function, too

MsgBox(4096, "", "Yesterday's Date: " & StringRegExpReplace (_DateAdd('D', -1, _NowCalcDate()), "(\d{2,4})-(\d{2})-(\d{2})", "$3/$2/$1"))

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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