The Daily Newbie - Using the DatePart Function
Posted: 2002-06-01
By: ArchiveBot
Viewed: 59
Filed Under:
No attachments for this post
Explains how to use the DatePart Function in Visual Basic.
Original Author: Matt Roberts
Code
The “To Start Things
content="text/html; charset=iso-8859-1">v:shapes="_x0000_s1027">
Daily Newbie
Off Right”
May 8,
2001
v:shapes="_x0000_s1027">
style="margin-left:135.0pt;text-indent:-135.0pt">face="Arial">Today’s Keyword:
size="4" face="Arial"> DatePart()
style="margin-left:135.0pt;text-indent:-135.0pt">face="Arial">Name Derived
From:
"Part of a Date"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:135.0pt;text-indent:-135.0pt">size="2" face="Arial">Used for:
Getting a part of a date value (i.e. Day, Month, Year, etc.).
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:135.0pt;text-indent:-135.0pt">size="2" face="Arial">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.
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:135.0pt;text-indent:-135.0pt">size="2" face="Arial">Syntax: Val=DatePart(Part, Date)
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:135.0pt;text-indent:-135.0pt">size="2" face="Arial">Usage: intWeekDay = DatePart("w","01/12/2000")
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:135.0pt;text-indent:-135.0pt">size="2" face="Arial">Parameters:
s - Seconds
n - Minutes
h - Hours
d - Days
y - Day of Year
w - Weekday
w - Week
m - Months
q - Quarter
yyyy - Year
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.
style="margin-left:135.35pt;text-indent:-135.35pt">face="Arial">Copy & Paste Code:
style="margin-left:135.35pt;text-indent:-135.35pt"> size="2" face="Arial">
style="margin-left:1.25in;text-indent:.35pt;tab-stops:45.8pt 91.6pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">size="3" face="Arial">
MsgBox "Today's Julian Date is: " & DatePart("y",Date) & "/" & DatePart("yyyy",Date)
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:135.0pt;text-indent:-135.0pt">
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.