Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get day, month and year from date 1

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
GB
How do you individually get the day, the month and the year from a date, in the format d/m/yyyy, so that day and month could be either 1 character or 2 characters?
 
You can use these functions in VBScript:

Day()
Month()
Year()

Eg.

today = Now()
Day(today) = 14
Month(today) = 12
Year(today) = 2006
 
I would be trying to get them from a string e.g. '9/12/2006', not from a datetime data type.
 
Ok if it is from a string then use the split function.

aryDateSplit = Split("09/12/2006","/")

Split returns an array, so you can get at the split values by doing something like:

strDay = aryDateSplit(0)
strMonth = aryDateSplit(1)
strYear = aryDateSplit(2)
 
If you want to convert them to numbers afterwards then check out the function CInt()
 
Thanks, I didn't know you could use the Split function in VB, thought it was just C# and Javascript ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top