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

Be the first to post comment on this article :

plus2net.com




Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer