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