The Daily Newbie Using the DatePart Function
Explains how to use the DatePart Function in Visual Basic.
Rate The Daily Newbie Using the DatePart Function
(3(3 Vote))
Daily Newbie - 05/01/2001
![]()
The
Daily Newbie
“To Start Things
Off Right”
May 8,
2001
![]()
Today’s Keyword:
DatePart()
Name Derived
From:
"Part of a Date"
Used for:
Getting a part of a date value (i.e. Day, Month, Year, etc.).
VB Help Description: Returns a Variant (Integer) containing the specified part of a given date.
Plain
English: Lets you get only one part of a date/time value. For example you can determine what weekday a certain date falls on.
Syntax: Val=DatePart(Part, Date)
Usage: intWeekDay = DatePart("w","01/12/2000")
Parameters:
Part - The part of the date you want returned . This can be:
s - Seconds
n - Minutes
h - Hours
d - Days
y - Day of Year
w - Weekday
w - Week
m - Months
q - Quarter
yyyy - Year
Date - The date that the part is derived from.
Example:
To get the current week within the current year (What week is this for the year? 1-52 )):
MsgBox DatePart("ww", Date)
If you have not read the Daily Newbie on how VB stores date format, you may want to review it now by clicking here.
Today's code snippet returns the Julian date for today.
Copy & Paste Code:
MsgBox "Today's Julian Date is: " & DatePart("y",Date) & "/" & DatePart("yyyy",Date)
The Daily Newbie Using the DatePart Function Comments
No comments yet — be the first to post one!
Post a Comment