Azurden
asked on
Format Date Time In ASP.... :-)
Ello All...
Ok here is todays 25 point question... ;-)
I made a script that will show the current day/month/year in the format I require. Now I have to take this and be able to add 3 years to the current year.
SO. If I was to have 00/00/0000 as my start in a form field "number one". I would require 00/00/0003 in a form field "number two".
Here is what I am using for the current date in the format I require below.
<%
yr = Year(Now())
mo = Month(Now())
da = Day(Now())
if len(mo)<2 then mo = "0" & mo
if len(da)<2 then da = "0" & da
%>
<%
Response.Write(mo &"/" & da & "/" & yr & "")
%>
So all I need is to be able to add 3 to the current year.
Any Takers? PLEASE
LTR
AZ
AGH!!!!! Just figured it out Doh!
<%
yr = Year(Now())
mo = Month(Now())
da = Day(Now())
if (yr)>0 then yr = yr + "3"
if len(mo)<2 then mo = "0" & mo
if len(da)<2 then da = "0" & da
%>
<%
Response.Write(mo &"/" & da & "/" & yr & "")
%>
SORRY!
Ok here is todays 25 point question... ;-)
I made a script that will show the current day/month/year in the format I require. Now I have to take this and be able to add 3 years to the current year.
SO. If I was to have 00/00/0000 as my start in a form field "number one". I would require 00/00/0003 in a form field "number two".
Here is what I am using for the current date in the format I require below.
<%
yr = Year(Now())
mo = Month(Now())
da = Day(Now())
if len(mo)<2 then mo = "0" & mo
if len(da)<2 then da = "0" & da
%>
<%
Response.Write(mo &"/" & da & "/" & yr & "")
%>
So all I need is to be able to add 3 to the current year.
Any Takers? PLEASE
LTR
AZ
AGH!!!!! Just figured it out Doh!
<%
yr = Year(Now())
mo = Month(Now())
da = Day(Now())
if (yr)>0 then yr = yr + "3"
if len(mo)<2 then mo = "0" & mo
if len(da)<2 then da = "0" & da
%>
<%
Response.Write(mo &"/" & da & "/" & yr & "")
%>
SORRY!
or you could convert to yyyymmdd , add 30000, convert it back
There's a much better way
DateAdd(Now(), 3, "yyyy")
gives you a date object exactly 3 years from now. It's extensible too. So you can add three days without having to deal with checking for "the 33rd of September" by going
DateAdd(Now(), 3, "d")
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdateadd.asp
DateAdd(Now(), 3, "yyyy")
gives you a date object exactly 3 years from now. It's extensible too. So you can add three days without having to deal with checking for "the 33rd of September" by going
DateAdd(Now(), 3, "d")
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdateadd.asp
Date + 3 * 365
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yeah, sorry. I did it from memory, which isn't doing so well these days. At least I included the link so he could look it up ;-)
just a note, cause its not always obvious, DateAdd is also used to subtract, just use negative numbers:
DateAdd("yyyy",-3,Now())
When working with to date values, you can also use DateDiff.
DateAdd("yyyy",-3,Now())
When working with to date values, you can also use DateDiff.
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
Unless it is clear to me that the question has been answered I will recommend delete. It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>
If the user does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp
Cd&
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
Unless it is clear to me that the question has been answered I will recommend delete. It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>
If the user does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp
Cd&
a_goat provided the correct answer to this question although the format of the code was not correct.
mikkolsoft provided the corrected version.
The point should go to one of these two.
My suggestion is one of the following:
Give points and grade less than A to a_goat
or
Give points and grade of A to mikkolsoft
mikkolsoft provided the corrected version.
The point should go to one of these two.
My suggestion is one of the following:
Give points and grade less than A to a_goat
or
Give points and grade of A to mikkolsoft
It is time to clean this abandoned question up.
I am putting it on a clean up list for CS.
<recommendation>
points to mikkolsoft
</recommendation>
If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.
Cd&
I am putting it on a clean up list for CS.
<recommendation>
points to mikkolsoft
</recommendation>
If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.
Cd&