Sign in to follow this  
Followers 0
ahab

Find date of different day in week

4 posts in this topic

#1 ·  Posted (edited)

edit: see my next post for how to do what I wanted to do

For today (July 1 2004)

@mday = 01

@mon = 07

@wday = 05

I'd like to figure out what the date was sunday.... (0627) or the date when @wday = 01 and have it work for any day of the year. :huh2: Maybe figure out what the month and date were thru @yday? :D

edit: see my next post for how to do what I wanted to do

Edited by ahab

Share this post


Link to post
Share on other sites



maybe you want to look at the date.au3 file in the include dir? there's udf's listed in the helpfile, all starting _date if you look in the index.

they might at least help you figure out how to write what you're looking for.

can you give some more context for what you're trying to do?


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Kinda like Marc's comic strip script It goes and downloads the picture files of the comic directly from a server and saves it to a local machine.

But there's a snag.

http://www.creators.com/0627/bs/bs0628g.gif

http://www.creators.com/ - static portion of the URL

0627 - the month, and... here's the hard part. Every sunday there is a folder made that contain's that week's comics. I could save data in an external file and do it from there, but I'd really rather not do that.

The rest of the URL is static or @mon or @mday, no big deal.

edit: working code below.

; needed for certain date functions (_DateLastMonthNum & _DateDaysInMonth)
#include <Date.au3>

; really only here to make coding easier and ensure uniformity
$ymd = @year & @mon & @mday

; figures out the @mday of sunday, since this might be last month and 
;end up a useless negative number things get a little complicated
$mdayofsunday = 01 - @wday + @mday

; I'd use flat out @mon, but like I said... things get complicated.
$month = @mon

;here's where they get complicated
if $mdayofsunday < 1 then

; if mdayofsunday ends up negative sunday of this week was last month
; so we figure out that date by subtracting that negative number from the
; number of days in the previous month
$mdayofsunday = $mdayofsunday + _DateDaysInMonth( _DateLastMonthNum( @mon ), @year)

; sets $month to the previous month
$month = _DateLastMonthNum( @mon )
endif

; takes all those dates, plugs them into one understandable URL to
; download, then saves it as an easier to understand local file
URLDownloadToFile("http://www.creators.com/" & $month & $mdayofsunday & "/bs/bs" & @mon & @mday & "g.gif", "bs" & $ymd & ".gif")

extra comments for your pleasure, feedback is welcome

Edited by ahab

Share this post


Link to post
Share on other sites

Here is a UDF that I made:

In your code, you call the function like this:

GetDate(1 Day Ago)

Func GetDate($1ReportDate)

Global $NewDay
Global $NewMonth
Global $NewYear
Global $TextMonth [15]

$Hour = @HOUR
$Minute = @MIN
$Day = @MDAY
$Month = @MON
$Year = @YEAR
$WeekDay = @WDAY
$HrEnd = " AM"
$DayList = "xx31|28|31|30|31|30|31|31|30|31|30|31"
$TextMonthArray = "January:February:March:April:May:June:July:August:September:October:November:December"
$TextMonth = StringSplit ( $TextMonthArray, ":" )


;Change hour format to am-pm
If $Hour > 12 Then
    $Hour = $Hour - 12
    $HrEnd = " PM"
EndIf


;Parse the $1ReportDate variable ($Argument2 $Argument1)
$SpacePos = StringInStr($1ReportDate," ")
$Argument1 = StringTrimLeft($1ReportDate,$SpacePos)
$Argument2 = StringLeft($1ReportDate,$SpacePos - 1)

If $Argument1 = "Sunday" And $Argument2 = "Previous" Then
;    MsgBox(0,"WDay Test","The day of the week is: " & @WDAY)
    $Argument2 = Int( 6 + $WeekDay )
    $Argument1 = "Days"
EndIf

If $Argument1 = "Sunday" And $Argument2 = "Last" Then
;    MsgBox(0,"WDay Test","The day of the week is: " & @WDAY)
    $Argument2 = Int( $WeekDay - 1 )
    $Argument1 = "Days"
EndIf

If $Argument1 = "Monday" And $Argument2 = "Previous" Then
;    MsgBox(0,"WDay Test","The day of the week is: " & @WDAY)
    $Argument2 = Int(5 + $WeekDay)
    $Argument1 = "Days"
EndIf

;MsgBox(0,"Test","$Argument1 = " & $Argument1 & @CRLF & "$Argument2 = " & $Argument2)


;If we need to subtract days, go here.
If $Argument1 = "Days" Then
    $NewDay = $Day - $Argument2
    $NewMonth = $Month
    $NewYear = $Year

    While $NewDay < 1
        $SubtractMonth = $NewMonth - 1
        
        If $SubtractMonth < 1 Then
            $SubtractMonth = 12
        EndIf
        
        $MonthEnd = StringMid( $DayList, $SubtractMonth * 3,5)
        If $SubtractMonth = 2 And Mod( $NewYear,4 ) = 0 Then
            $MonthEnd = 29
        EndIf
        
        $NewDay = $NewDay + $MonthEnd
        $NewMonth = $NewMonth - 1
        
        If $NewMonth < 1 Then
            $NewMonth = 12
            $NewYear = $NewYear - 1
        EndIf
        
    Wend

EndIf

;If we need to subtract months, go here.
If $Argument1 = "Months" Then
    $NewDay = $Day
    $NewMonth = $Month - $Argument2
    $NewYear = $Year

    While $NewMonth < 1
        $NewMonth = $NewMonth + 12
        $NewYear = $NewYear - 1
    Wend
EndIf

;If we need to subtract years, go here.

If $Argument1 = "Years" Then
    $NewDay = $Day
    $NewMonth = $Month
    $NewYear = $Year - $Argument2
EndIf

Return $TextMonth[$NewMonth] & " " & $NewDay & ", " & $NewYear
MsgBox( 0,"Date","The Date is: " & $Month & "/" & $Day & "/" & $Year & @CRLF & "The Time is: " & $Hour & ":" & $Minute & $HrEnd)
MsgBox( 0,$1ReportDate & " Before Date","The Date " & $1ReportDate & " ago was: " & $NewMonth & "/" & $NewDay & "/" & $NewYear & @CRLF & "The Time is: " & $Hour & ":" & $Minute & $HrEnd)

EndFunc

(I don't know how this will look. It's the first time I've used this thing.)

Take care,

-Dw

---

Let's split up, we can do more damage that way.

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