Jump to content

_GetDate()


Joke758
 Share

Recommended Posts

Convert any date ( >1900 ) to a day of the week!

Exemple: 14 April 2007 is a Saturday

23 September 49302 is a Thursday

;By Joke758
#include <Date.au3>
$day = Inputbox ( "Date to Day", "Day (1-31)", "", "", -1, 100, -1, -1 )
$Month = Inputbox ( "Date to Day", "Month (1-12)", "", "", -1, 100, -1, -1 )
$Year = Inputbox ( "Date to Day", "Year (1900-infinite)", "", "", -1, 100, -1, -1 )
$a = _GetDay ( $day, $month, $year )

If $a = 0 Then 
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Sunday" )
ElseIf $a = 1 Then 
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Monday" )
ElseIf $a = 2 Then 
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Tuesday" )
ElseIf $a = 3 Then 
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Wednesday" )
ElseIf $a = 4 Then 
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Thursday" )
ElseIf $a = 5 Then
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Friday" )
ElseIf $a = 6 Then 
    Msgbox ( 64, "Day", $day&" "&_DateMonthOfYear($month, 0)&" "&$year&" is a Saturday" )
Else
    Msgbox ( 16, "Day", "Error" )
EndIf



;===============================================================================
;
; Description:          _GetDay
; Parameter(s):     $iDay - Day (1-31)
;                   $iMonth - Month (1-12)
;                   $iYear - Year (1900-infinite)
; Requirement:          <Date.au3>
; Return Value(s):  The return value is 0 to 6.
;                       0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
; Author(s):            Joke758
; Note(s):              $iYear must be higher than 1899
;
;===============================================================================
Func _GetDay ( $iDay, $iMonth, $iYear)
    Local $aDayValue = StringSplit ( "1,4,4,0,2,5,0,3,6,1,4,6", "," )
    Select
        Case __DateIsValidEx($iYear&"/"&$iMonth&"/"&$iDay) and $iYear >= 1900
            $i_Year = StringTrimRight ( $iYear, 2 )-19&StringRight ( $iYear, 2 )
            $iSum = Mod ( Mod ( Mod ( Mod ( Int ( $i_Year/12 )+Mod ( $i_Year, 12 ), 7 ) + Int ( Mod ( $i_Year, 12 ) / 4 ), 7 ) + $aDayValue[$iMonth], 7 ) + $iDay, 7 )
            If _DateIsLeapYear ( $iYear ) = 1 and $iMonth <= 2 and $iDay <= 29 Then $iSum = $iSum-1
            If $iSum <= 0 Then $iSum = $iSum + 7
            Return $iSum-1
        Case Else
            SetError ( 1 )
            Return -1
    EndSelect
EndFunc

Func __DateIsValidEx($sDate)
    Local $asDatePart[4]
    Local $asTimePart[4]
    Local $iNumDays
    $iNumDays = "31,28,31,30,31,30,31,31,30,31,30,31"
    $iNumDays = StringSplit($iNumDays, ",")
    ; split the date and time into arrays
    _DateTimeSplit($sDate, $asDatePart, $asTimePart)
    If $asDatePart[0] <> 3 Then
        Return (0)
    EndIf
    ; verify valid input date values
    If _DateIsLeapYear($asDatePart[1]) Then $iNumDays[2] = 29
    If $asDatePart[2] < 1 Or $asDatePart[2] > 12 Then Return (0)
    If $asDatePart[3] < 1 Or $asDatePart[3] > $iNumDays[$asDatePart[2]] Then Return (0)
    Return (1)
EndFunc
:P

[u]My Programs:[/u]Word Search Creator - Make your own Word SearchShortHand - Hide a secret message in a jpg fileHex Editor - Edit your Binary fileIncrease file size - Increase the size of any filesArt Generator - A program that generate random picture[u]My Functions:[/u]16-Bits Hash - My Hash function similar to MD5Probabilities - My probabilities function (factorial, permuation, combination)_GetDate() - Convert a date to a day of the week_Base(), _Dec() - Convert a number in any base (bin, oct, hex, dec). Create your own!

Link to comment
Share on other sites

Oops, I didn't see them :P

[u]My Programs:[/u]Word Search Creator - Make your own Word SearchShortHand - Hide a secret message in a jpg fileHex Editor - Edit your Binary fileIncrease file size - Increase the size of any filesArt Generator - A program that generate random picture[u]My Functions:[/u]16-Bits Hash - My Hash function similar to MD5Probabilities - My probabilities function (factorial, permuation, combination)_GetDate() - Convert a date to a day of the week_Base(), _Dec() - Convert a number in any base (bin, oct, hex, dec). Create your own!

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...