Sign in to follow this  
Followers 0
huskies

turn 2009/03/14 into year month and day

8 posts in this topic

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

is there one that can split the date?


<It Shall Be Done>

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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  

Share this post


Link to post
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")

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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>

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
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>

Share this post


Link to post
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.

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