Sign in to follow this  
Followers 0
happy2help

Help with DATE

7 posts in this topic

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!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


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

Share this post


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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


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

Share this post


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

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
Sign in to follow this  
Followers 0