Jump to content

_date


yucatan
 Share

Recommended Posts

So if one can get all the Mondays ... ?

#include <Date.au3>
$Year = '2010'
$Month = '01'
$Day = '01'
$sDate = $Year & "/" & $Month & "/" & $Day
$iIndex = 1
$iIndex2 = 1
$asDatePart = ""
$iTimePart = ""
While 1
    _DateTimeSplit($sDate, $asDatePart, $iTimePart)
    If $asDatePart[1] > $Year Then ExitLoop
    $Week_No = _WeekNumberISO($Year, $asDatePart[2], $asDatePart[3])
    $Day_No = _DateToDayOfWeek($Year, $asDatePart[2], $asDatePart[3])
    If $Week_No = $iIndex2 Then
        ConsoleWrite($sDate & " " & $Week_No & " " & _DateDayOfWeek($Day_No, 0) _
        & " " & $asDatePart[3] & " " & _DateToMonth($asDatePart[2]) & @CRLF)
        $iIndex2 += 1
    EndIf
    $sDate = _DateAdd("d", $iIndex, $sDate)
WEnd
MsgBox(0, '', 'Like so?', .5)
Edited by JoHanatCent
Link to comment
Share on other sites

To check when a week starts without Outlook, try this example of GUICtrlCreateMonthCal() with week numbers.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <GuiMonthCal.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Date, $msg, $aDate
    GUICreate("Get date", 220, 190)

    ; From AutoIt help file - MonthCal Styles
    ; $MCS_WEEKNUMBERS - 0x04 - The month calendar control will display week numbers (1-52) to the left
    ; of each row of days. Week 1 is defined as the first week that contains at least four days.
    ; First_week definitions - http://en.wikipedia.org/wiki/ISO_week_date#First_week
    $Date = GUICtrlCreateMonthCal("2010/01/01", 10, 10, -1, -1, 0x04)
    GUISetState()

    Do
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Date
                Do
                    Sleep(10)
                Until Not _IsPressed("01")
                $aDate = StringSplit(GUICtrlRead($Date), "/", 2)
                _GUICtrlMonthCal_SetCurSel($Date, $aDate[0], $aDate[1], $aDate[2])
                MsgBox(0, "Date", $aDate[2] & "/" & $aDate[1] & "/" & $aDate[0], 1)
        EndSwitch
    Until 0
    Return
EndFunc   ;==>Example

Edit: Note- Click on the year and an "UpDown" control appears.

Edited by Malkey
Link to comment
Share on other sites

i would like to do this with different years.

so from 2010 to 2050

this is my code.

#include <Date.au3>
$Year = '2010'
$Month = '01'
$Day = '01'
$sDate = $Year & "/" & $Month & "/" & $Day
$iIndex = 1
$iIndex2 = 1
$asDatePart = ""
$iTimePart = ""

While 1
    _DateTimeSplit($sDate, $asDatePart, $iTimePart)
    If $asDatePart[1] > $Year Then
    $Year +=1
    if $year = "2050" then ExitLoop
    endif
   $Week_No = _WeekNumberISO($Year, $asDatePart[2], $asDatePart[3])
    $Day_No = _DateToDayOfWeek($Year, $asDatePart[2], $asDatePart[3])
    If $Week_No = $iIndex2 Then
        ConsoleWrite($sDate & " " & $Week_No & " " & _DateDayOfWeek($Day_No, 0) _
        & " " & $asDatePart[3] & " " & _DateToMonth($asDatePart[2]) & @CRLF)
        $iIndex2 += 1
    EndIf
    $sDate = _DateAdd("d", $iIndex, $sDate)
WEnd
MsgBox(0, '', 'Like so?', .5)
Edited by yucatan
Link to comment
Share on other sites

O .. I thought it was mine! ;>

#include <Date.au3>
$Year = '2010'
$YearToEnd = '2050'
$Month = '01'
$Day = '01'
$sDate = $Year & "/" & $Month & "/" & $Day
$iIndex = 1
$iIndex2 = 1
$asDatePart = ""
$iTimePart = ""

While 1
    _DateTimeSplit($sDate, $asDatePart, $iTimePart)
    if $asDatePart[1] > $YearToEnd  Then ExitLoop
if  $iIndex2 > 52 then $iIndex2 = 1

   $Week_No = _WeekNumberISO($Year, $asDatePart[2], $asDatePart[3])
    $Day_No = _DateToDayOfWeek($Year, $asDatePart[2], $asDatePart[3])
    If $Week_No = $iIndex2 Then
        ConsoleWrite($sDate & " " & $Week_No & " " & _DateDayOfWeek($Day_No, 0) _
        & " " & $asDatePart[3] & " " & _DateToMonth($asDatePart[2]) & @CRLF)
        $iIndex2 += 1
    EndIf
    $sDate = _DateAdd("d", $iIndex, $sDate)
WEnd
MsgBox(0, '', 'Like so?', .5)

Edit:

I saw something about an array? What dit you want to see inside?

Like $weekY2010[1] = "Dates & Dates"?

Edited by JoHanatCent
Link to comment
Share on other sites

O .. I thought it was mine! ;>

#include <Date.au3>
$Year = '2010'
$YearToEnd = '2050'
$Month = '01'
$Day = '01'
$sDate = $Year & "/" & $Month & "/" & $Day
$iIndex = 1
$iIndex2 = 1
$asDatePart = ""
$iTimePart = ""

While 1
    _DateTimeSplit($sDate, $asDatePart, $iTimePart)
    if $asDatePart[1] > $YearToEnd  Then ExitLoop
if  $iIndex2 > 52 then $iIndex2 = 1

   $Week_No = _WeekNumberISO($Year, $asDatePart[2], $asDatePart[3])
    $Day_No = _DateToDayOfWeek($Year, $asDatePart[2], $asDatePart[3])
    If $Week_No = $iIndex2 Then
        ConsoleWrite($sDate & " " & $Week_No & " " & _DateDayOfWeek($Day_No, 0) _
        & " " & $asDatePart[3] & " " & _DateToMonth($asDatePart[2]) & @CRLF)
        $iIndex2 += 1
    EndIf
    $sDate = _DateAdd("d", $iIndex, $sDate)
WEnd
MsgBox(0, '', 'Like so?', .5)

Edit:

I saw something about an array? What dit you want to see inside?

Like $weekY2010[1] = "Dates & Dates"?

i'm trying to get $week1[1] = the first date of the first week

$week1[2]= the second date of the first week

$week1[3]= the thirt date of the first week

do this until i have all 7 dates of this week

then

$week2[1] = the first date of the second week

$week2[2] = the second date of the second week.

my main target is that if i'm asking my script calc what dates belong in week 35 of 2009

what is week 35 of 2009?

is days monday 12 november 2009.

truesday 13 november 2009.

etc

Link to comment
Share on other sites

i'm trying to get $week1[1] = the first date of the first week

$week1[2]= the second date of the first week

$week1[3]= the thirt date of the first week

do this until i have all 7 dates of this week

then

$week2[1] = the first date of the second week

$week2[2] = the second date of the second week.

my main target is that if i'm asking my script calc what dates belong in week 35 of 2009

what is week 35 of 2009?

is days monday 12 november 2009.

truesday 13 november 2009.

etc

Hello guys,

I'm trying to calculate all dates and weeknumbers.

the problem is that i get this dinsdag 2012/01/02 instead of Dinsdag 2 Januari.

this is my code

#include <Array.au3>
#include <Date.au3>
local $week[55][8]
$YearToEnd = @YEAR +2
$year = @year -2
$Month = '01'
$Day = '01'
$sDate = $year & "/" & $Month & "/" & $Day
$iIndex = 1
$iIndex2 = 1
$asDatePart = ""
$iTimePart = ""
$displayday = ""

While 1
    _DateTimeSplit($sDate, $asDatePart, $iTimePart)
    if $asDatePart[1] > $YearToEnd  Then ExitLoop
if  $iIndex2 > 52 then $iIndex2 = 1

   $Week_No = _WeekNumberISO($year, $asDatePart[2], $asDatePart[3])
    $Day_No = _DateToDayOfWeek($year, $asDatePart[2], $asDatePart[3])
    If $Week_No = $iIndex2 Then
        ;ConsoleWrite($sDate & " " & $Week_No & " " & _DateDayOfWeek($Day_No, 0) & " " & $asDatePart[3] & " " & _DateToMonth($asDatePart[2]) & @CRLF)

        if _DateDayOfWeek($Day_No, 0) = "Monday" then $displayday = "Maandag"
        if _DateDayOfWeek($Day_No, 0) = "Tuesday" then $displayday = "Dinsdag"
        if _DateDayOfWeek($Day_No, 0) = "Wensday" then $displayday = "Woensdag"
        if _DateDayOfWeek($Day_No, 0) = "Thursday" then $displayday = "Donderdag"
        if _DateDayOfWeek($Day_No, 0) = "Friday" then $displayday = "Vrijdag"
        if _DateDayOfWeek($Day_No, 0) = "Saturday" then $displayday = "Zaterdag"
        if _DateDayOfWeek($Day_No, 0) = "Sunday" then $displayday = "Zondag"

        if _DateToMonth($asDatePart[2]) = "January" then $displaymonth = "Januari"
        if _DateToMonth($asDatePart[2]) = "February" then $displaymonth = "Februari"
        if _DateToMonth($asDatePart[2]) = "March" then $displaymonth = "Maart"
        if _DateToMonth($asDatePart[2]) = "April" then $displaymonth = "April"
        if _DateToMonth($asDatePart[2]) = "May" then $displaymonth = "Mei"
        if _DateToMonth($asDatePart[2]) = "June" then $displaymonth = "Juni"
        if _DateToMonth($asDatePart[2]) = "July" then $displaymonth = "Juli"
        if _DateToMonth($asDatePart[2]) = "August" then $displaymonth = "Augustus"
        if _DateToMonth($asDatePart[2]) = "September" then $displaymonth = "September"
        if _DateToMonth($asDatePart[2]) = "October" then $displaymonth = "October"
        if _DateToMonth($asDatePart[2]) = "November" then $displaymonth = "November"
        if _DateToMonth($asDatePart[2]) = "December" then $displaymonth = "December"






        $week[$Week_No][0] = $displayday  &" "& $asDatePart[3] &" "& $displaymonth
        $week[$Week_No][1] = $displayday  &" "& _DateAdd( 'd',1, $sDate) &" "& $displaymonth
        $week[$Week_No][2] = $displayday  &" "& _DateAdd( 'd',2, $sDate) &" "& $displaymonth
        $week[$Week_No][3] = $displayday  &" "& _DateAdd( 'd',3, $sDate) &" "& $displaymonth
        $week[$Week_No][4] = $displayday  &" "& _DateAdd( 'd',4, $sDate) &" "& $displaymonth
        $week[$Week_No][5] = $displayday  &" "& _DateAdd( 'd',4, $sDate) &" "& $displaymonth
        $week[$Week_No][6] = $displayday  &" "& _DateAdd( 'd',5, $sDate) &" "& $displaymonth
        $week[$Week_No][7] = $displayday  &" "& _DateAdd( 'd',6, $sDate) &" "& $displaymonth

        $iIndex2 += 1
        EndIf
    $sDate = _DateAdd("d", $iIndex, $sDate )
WEnd
_ArrayDisplay($week, "Class List of Active Window")
Link to comment
Share on other sites

This part should solve that:

$week[$Week_No][0] = $displayday  &" "& $asDatePart[3] &" "& $displaymonth
        $week[$Week_No][1] = $displayday  &" "& StringRight(_DateAdd( 'd',1, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][2] = $displayday  &" "& StringRight(_DateAdd( 'd',2, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][3] = $displayday  &" "& StringRight(_DateAdd( 'd',3, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][4] = $displayday  &" "& StringRight(_DateAdd( 'd',4, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][5] = $displayday  &" "& StringRight(_DateAdd( 'd',4, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][6] = $displayday  &" "& StringRight(_DateAdd( 'd',5, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][7] = $displayday  &" "& StringRight(_DateAdd( 'd',6, $sDate), 2) &" "& $displaymonth

Link to comment
Share on other sites

Here is an example of the function _WeekDates().

Given the year and the week number of that year, returns is an array of all the dates of that week in Dutch.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <GuiMonthCal.au3>
#include <Date.au3>
#include <Array.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Date, $msg, $aDate, $aResult, $iWeekNumber
    GUICreate("Get date", 220, 190)

    ; From AutoIt help file - MonthCal Styles
    ; $MCS_WEEKNUMBERS - 0x04 - The month calendar control will display week numbers (1-52) to the left
    ; of each row of days. Week 1 is defined as the first week that contains at least four days.
    ; First_week definitions - http://en.wikipedia.org/wiki/ISO_week_date#First_week
    $Date = GUICtrlCreateMonthCal("2010/01/01", 10, 10, -1, -1, 0x04)
    GUISetState()

    Do
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Date
                Do
                    Sleep(10)
                Until Not _IsPressed("01")
                $aDate = StringSplit(GUICtrlRead($Date), "/", 2)
                _GUICtrlMonthCal_SetCurSel($Date, $aDate[0], $aDate[1], $aDate[2])
                $iWeekNumber = _WeekNumberISO($aDate[0], $aDate[1], $aDate[2])
                $aResult = _WeekDates($aDate[0], $iWeekNumber)
                _ArrayDisplay($aResult, "Dates for week No. " & $iWeekNumber)
        EndSwitch
    Until 0
    Return
EndFunc   ;==>Example


; Parameters - $iWeek is the week number for the year ($Year).
; Returns an array containing all the dates of the specified week in Dutch.
Func _WeekDates($Year, $iWeek)
    Local $aDayOfWeek[7] = ["Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonth[13] = ["", "Januari", "Februari", "Maart", "April", "Mei", "Juni", _
            "Juli", "Augustus", "September", "October", "November", "December"]
    Local $aRes[7], $MonFstWeek, $FstDateOfWeek, $sDays, $aTemp

    $MonFstWeek = _DateAdd("d", 1 - _DateToDayOfWeekISO($Year, 1, 4), $Year & "/01/04")
    $FstDateOfWeek = _DateAdd("d", ($iWeek - 1) * 7, $MonFstWeek)

    For $i = 0 To 6
        $sDays = _DateAdd("d", $i, $FstDateOfWeek)
        $aTemp = StringSplit($sDays, "/", 2)
        $aRes[$i] = $aDayOfWeek[$i] & ", " & $aTemp[2] & " " & $aMonth[$aTemp[1]] & ", " & $aTemp[0]
    Next
    Return $aRes
EndFunc   ;==>_WeekDates
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...