VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The Daily Newbie Using the DatePart Function

by Matthew Roberts (26 Submissions)
Category: Coding Standards
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Explains how to use the DatePart Function in Visual Basic.

Rate The Daily Newbie Using the DatePart Function



content="text/html; charset=iso-8859-1">
Daily Newbie - 05/01/2001


 


v:shapes="_x0000_s1027">


The
Daily Newbie


“To Start Things
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:          



  • 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. 


    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"> 








    Download this snippet    Add to My Saved Code

  • The Daily Newbie Using the DatePart Function Comments

    No comments have been posted about The Daily Newbie Using the DatePart Function. Why not be the first to post a comment about The Daily Newbie Using the DatePart Function.

    Post your comment

    Subject:
    Message:
    0/1000 characters