SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Collecting parts of Date by using DatePart function

We can collect part of the date like year, month, day, date, Weekday etc from date by using DatePart function in VBScript used in ASP. We can extract the required date portion from the full date or date variable. Here is the syntax of the DatePart function.


DatePart(date_type, date)



Here date_type is the type of date part we want to get like Day, month, year, week etc. date is the date variable or a fixed date figure. Here is the code to display month part from today's date.


Dim d_today
d_today=Now
Response.Write DatePart("m",d_today)


Above code will return month in number for today's date. By changing date_type argument to different values we can get year, day , day of the year etc by using this function.

Let us try to collect year from a fixed date . Here is the example

Response.Write DatePart("yyyy",#09/10/2003#)
We will get an out put of 2003

We can also get the Date, Month or year by using Day(date), Month(date) and Year(date) function respectively. For example

year(#10/15/2003#)
This will give 2003 as output.

Month(#10/15/2003#)
This will give 10 as output.

Day(#10/15/2003#)
This will give 15 as output.

Click here to get similar function in PHP to get date parts

Further readings
Getting todays Date and Time based on local settings
Formatting date and time on local settings
Adding Date intervals using DateAdd function
Finding difference between two dates using DateDiff function
Collecting parts of Date by using DatePart function
Collecting Month name by using Month number by MonthName function
Collecting Name of the weekday of any Date by WeekDayName function
Generating Date variables by using Month, Day and Year Value
Function IsDate to check valid date or date variable
Checking user entered date value
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.