Sign in to follow this  
Followers 0
mschol

calculating date

6 posts in this topic

i need to do the following:

i need to fill in a date on a website.

but the date to fill in depends on the current date:

example:

1 when its tuesday 24-07-07 i need to fill in 23-07-07 (monday)

but

2 when its monday 23-07-07 i need to fill in 20-07-07 (friday)

how do i do that with autoit?

(i need the values (day/month/year) as separate variables)

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

@mschol

This calculates 2 days back from today.

#include<date.au3>
$iWeekday = _DateToDayOfWeekISO (@YEAR, @MON, @MDAY)
$NextMonday = _DateAdd("d",-2-$iWeekday,_NowCalcDate())
ConsoleWrite('Next Monday is ' & $NextMonday & @crlf )

regards

ptrex

1: the example you gave gives back 2007-07-21 which is 3 days ago :whistle:

and i think you dont get what i need to have:

i need to find the last work day based on the current date, so:

if today is monday then get date of last friday

if today is tuesday then get date of last monday

if today is wednesday then get date of last tuesday

if today is thursday then get date of last wednesday

if today is friday then get date of last thursday

hope this makes my question a little clearer

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The example posted goes back to the last Monday..

This goes back 2 days from today:

#include<date.au3>
$day = _DateAdd("d",-2,_NowCalcDate())
ConsoleWrite('Two days agoy is ' & $day & @crlf )
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

1: the example you gave gives back 2007-07-21 which is 3 days ago :lmao:

and i think you dont get what i need to have:

i need to find the last work day based on the current date, so:

if today is monday then get date of last friday

if today is tuesday then get date of last monday

if today is wednesday then get date of last tuesday

if today is thursday then get date of last wednesday

if today is friday then get date of last thursday

hope this makes my question a little clearer

Try this:

#include<date.au3>
$day = _PreviousWorkDay()
ConsoleWrite('Last work day was: ' & $day & @crlf )

Func _PreviousWorkDay()
    Local $Offset
    Switch @WDAY
        Case 1
            $Offset = -2
        Case 2
            $Offset = -3
        Case Else
            $Offset = -1
    EndSwitch
    Return _DateAdd("d", $Offset, _NowCalcDate())
EndFunc

:whistle:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Try this:

#include<date.au3>
$day = _PreviousWorkDay()
ConsoleWrite('Last work day was: ' & $day & @crlf )

Func _PreviousWorkDay()
    Local $Offset
    Switch @WDAY
        Case 1
            $Offset = -2
        Case 2
            $Offset = -3
        Case Else
            $Offset = -1
    EndSwitch
    Return _DateAdd("d", $Offset, _NowCalcDate())
EndFuncoÝ÷ Ûú®¢×§Ç¢Ø^槶)Ê%½çb¶X¤zØb±«­¢+ØÀÌØí¥]­äô}ÑQ½å=]­%M

with the complete date in the $date array

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