Sign in to follow this  
Followers 0
NewbieAussieScripter

Help with past dates

7 posts in this topic

#1 ·  Posted (edited)

G'day. I thought this would be easy but am having trouble with the logic. I need to work out the date of the previous weeks Monday and the previous Sunday for a report. ie: The report is run on say Tuesday 18 September 2007. I need to figure out how to get the date for the Monday in the previous week (10 Sptember 2007) and the Sunday after (16 September 2007). I'm assuming if I can work out the Monday's date, I could just do something like RETURN (@DAY + 6) or some such. I'm bamboozled. Please help. Cheers.

Edited by NewbieAussieScripter

Share this post


Link to post
Share on other sites



Welcome to the AutoIt forums!

A general piece of advice here is to post the code you're having problems with so that other people can fully understand your problem and what you're trying to do.

I think that would be a good suggestion for this time. However, I'll try to think of something in a second.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

look for 'date.au3' in the help file. I'm sure you can do it with those UDF's :)

Share this post


Link to post
Share on other sites

look for 'date.au3' in the help file. I'm sure you can do it with those UDF's :)

Thanks Nahuel. I had a look and thought I could use some combination of DateDiff and NowDateCalc but have become lost. This is why I'm putting in this request for help. Most of the answers I read in this forum have been plain to understand which is what I need. Reading the Help file and reviewing the date.au3 file showed me that I should be able to do it but cannot figure out the logic of what I need to do.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <Date.au3>
Local $sDate = _DateAdd ( "D", -7, _NowCalc ())
MsgBox(1, "One week ago today", $sDate)

#include <Date.au3>
Local $sDate = _DateAdd ( "D", -7, _NowCalc ())

MsgBox(1, "One week ago", _DateTimeFormat($sDate, 1))

This one should be what your looking for.

Edited by Chip

Share this post


Link to post
Share on other sites

#include <Date.au3>
Local $sDate = _DateAdd ( "D", -7, _NowCalc ())
MsgBox(1, "One week ago today", $sDate)

#include <Date.au3>
Local $sDate = _DateAdd ( "D", -7, _NowCalc ())

MsgBox(1, "One week ago", _DateTimeFormat($sDate, 1))

This one should be what your looking for.

Thanks Chip. This is kind of what I had in mind and would certainly work if the report was run on a Monday. However, it is not always run on the same day each week. Usually, it is run on a Tuesday but sometimes it can be Thursday before it is run. Therefore the "-7" would produce an incorrect result. So I guess, in refining my question, how do I verify that the date returned is in fact, the Monday from the previous week? I would also like to add my sincere thanks for the speed and constuctive support from the community here. I must admit, being "Down Under", I thought I'd be waiting until tomorrow at the earliest for a response. This is helping me an awful lot. Thanks again, Bonk.

Share this post


Link to post
Share on other sites

you could take a look also in the help file at macros - here is the content:

Macro Reference - Time And Date

Below is a list of Time and Date macros. Notice that most return values are two-digits long.

The full list of macros can be found here.

Macro Description

@SEC

Seconds value of clock. Range is 00 to 59

@MIN

Minutes value of clock. Range is 00 to 59

@HOUR

Hours value of clock in 24-hour format. Range is 00 to 23

@MDAY

Current day of month. Range is 01 to 31

@MON

Current month. Range is 01 to 12

@YEAR

Current four-digit year

@WDAY

Numeric day of week. Range is 1 to 7 which corresponds to Sunday through Saturday.

@YDAY

Current day of year. Range is 1 to 366 (or 365 if not a leap year)

You can see that @WDAY is very useful for what you have in mind :)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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