Format Date and Time Script in ASP
Hi friends,
I want to change the formats of the date and time in ASP. Since I have recently started I don't know much about the ASP. I have done that changes but in Java. Anyone out there can tell me what are the Formats of Date and Time Script in ASP..?? Please guide me about the functions that are used for the same..!! Need help as earlier as possible.!! :notworthy
Re: Format Date and Time Script in ASP
If you want to check the Date or Time in ASP, you can use the FormatDateTime(). The inbuild function called FormatDateTime() is very useful for ASP. For getting the current date and time in ASP, you can use the now() function. You can use the code as mentioned below :
Code:
<%
dim todaysDate
todaysDate=now()
%>
By doing this you will get the Current Date and Time.
Re: Format Date and Time Script in ASP
I have provided you with some format of Date, just have a look on that :
If you want to check today's date then you can use the todaysDate :
Code:
<%
Response.write todaysDate
%>
The output of the above would be :
Code:
RESULT: 2/10/2010 2:09:59 AM
If you want to display the date as long date then use the following code :
Code:
<%
Response.write FormatDateTime(todaysDate,1)
%>
The output for the above code would be :
Code:
RESULT: Wednesday, February 10, 2010
Re: Format Date and Time Script in ASP
I have tried to give some more examples for checking the weekdays. You can use the following commands for the same :
Code:
<% = weekday(now) %>
The above command will show the day in week by its number.
If you want to show a name of a day in a week, use the below command :
Code:
<% = weekdayname(weekday(now)) %>
If you want to check the number of the month in a year, then type the following command :
For showing the name of the month you can use :
Code:
<% = monthname(month(now)) %>
Re: Format Date and Time Script in ASP
You can also auto-update the year in ASP. I have provided with a script that can auto-update the year displayed :
Code:
<%
Function CorrectCopyrightYear (CreationYear)
If Year(Now) > CreationYear Then
CorrectCopyrightYear = CreationYear & "-" & Year(Now)
Else
CorrectCopyrightYear = CreationYear
End If
End Function
%>
Hope that you find this useful.