Jump to content

turn 2009/03/14 into year month and day


Recommended Posts

with _DateTimeSplit it can split 2005/01/01 14:30 into date and time

is there one that can split the date?

Use string functions:

$date = '2005/01/01 14:30'
$year = StringLeft($date, 4)
$mon  = StringMid($date, 6, 2)
$day  = StringMid($date, 9, 2)
MsgBox(0, 'Date', 'Year: ' & $year & @LF & 'Month: ' & $mon & @LF  & 'Day: ' & $day)
; or with split
$aDate = StringSplit(StringTrimRight($date, 6), '/')
MsgBox(0, 'Date with StringSplit', 'Year: ' & $aDate[1] & @LF & 'Month: ' & $aDate[2] & @LF  & 'Day: ' & $aDate[3])
Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

Why not use _DateTimeSplit and just ignore the time values

#include <Date.au3>
#include <Array.au3>
Dim $MyDate
Dim $MyTime

_DateTimeSplit("2009/03/17", $MyDate, $MyTime)
_ArrayDisplay($MyDate,"Date Info")

I meant how to turn 2009/03/17 into 2009 ,March and 17. I don't have a time variable, that was just an example.

@BugFix, thank you , it was a very good idea!

Edited by huskies
<It Shall Be Done>
Link to comment
Share on other sites

I meant how to turn 2009/03/17 into 2009 ,March and 17. I don't have a time variable, that was just an example.

@BugFix, thank you , it was a very good idea!

This would give you the name of the month if that is what you are looking for...

#include <Date.au3>
Dim $MyDate
Dim $MyTime

_DateTimeSplit("2009/03/17", $MyDate, $MyTime)

$Year = $MyDate[1]
$Month = _DateToMonth($MyDate[2],0)
$Day = $MyDate[3]

MsgBox(0,"","Year: " & $Year & @CRLF & "Month: " & $Month & @CRLF & "Day: " & $Day)
Link to comment
Share on other sites

I meant how to turn 2009/03/17 into 2009 ,March and 17. I don't have a time variable, that was just an example.

@BugFix, thank you , it was a very good idea!

I had to create this for someone a few months back. Modify it to your hearts content.

#Include <Date.au3>



MsgBox(0, "",   _DateSubtract(-1))


Func _DateSubtract($iSubtract)

    Local $Days[7] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
    Local $Month[12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

    $Split = StringSplit(_DateAdd('d', $iSubtract, _NowCalcDate()), "/")
    $CurentDate = $Days[_DateToDayOfWeekISO($Split[1], $Split[2], $Split[3])] & ", " & $Month[$Split[2] - 1] & " " & $Split[3] & ", " & $Split[1]

    Return $CurentDate
EndFunc
Link to comment
Share on other sites

This would give you the name of the month if that is what you are looking for...

#include <Date.au3>
Dim $MyDate
Dim $MyTime

_DateTimeSplit("2009/03/17", $MyDate, $MyTime)

$Year = $MyDate[1]
$Month = _DateToMonth($MyDate[2],0)
$Day = $MyDate[3]

MsgBox(0,"","Year: " & $Year & @CRLF & "Month: " & $Month & @CRLF & "Day: " & $Day)
thank you, so in here is $myDate separating the 2009/03/17 into 3 arrays based on the slash "/" or does this only work on dates? say if i had "random/whatever/don'tknow" would it work?

$Year = $MyDate[1]
$Month = $MyDate[2]
$Day = $MyDate[3]
<It Shall Be Done>
Link to comment
Share on other sites

thank you, so in here is $myDate separating the 2009/03/17 into 3 arrays based on the slash "/" or does this only work on dates? say if i had "random/whatever/don'tknow" would it work?

$Year = $MyDate[1]
$Month = $MyDate[2]
$Day = $MyDate[3]
If you try "random/whatever/don'tknow" each of the elements in $MyDate contains -1. So, you must have something that resembles a date in the format of yyyy/mm/dd in order for the function to work.
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...