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


This will give 2003 as output.


This will give 10 as output.


This will give 15 as output.

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

Be the first to post comment on this article :


Post Comment This is for short comments only. Use the forum for more discussions.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 All rights reserved worldwide Privacy Policy Disclaimer