• Status: Solved
• Priority: Medium
• Security: Public
• Views: 166

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.

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!
0
Azurden
• 2
• 2
• 2
• +3
1 Solution

Commented:
or you could convert to yyyymmdd , add 30000, convert it back
0

Commented:
There's a much better way

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

0

Commented:
Date + 3 * 365
0

Commented:
a_goat: should be

and

right? :)

Mikkol
0

Commented:
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 ;-)
0

Commented:
just a note, cause its not always obvious, DateAdd is also used to subtract, just use negative numbers:

When working with to date values, you can also use DateDiff.
0

Commented:
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:
http://www.experts-exchange.com/help/closing.jsp

Cd&

0

Commented:
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
0

Commented:
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,