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

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!
0
Azurden
Asked:
Azurden
  • 2
  • 2
  • 2
  • +3
1 Solution
 
HamdyHassanCommented:
or you could convert to yyyymmdd , add 30000, convert it back
0
 
a_goatCommented:
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
0
 
aelatikCommented:
Date + 3 * 365
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mikkolsoftCommented:
a_goat: should be

DateAdd("yyyy", 3, Now())
and
DateAdd("d", 3, Now())

right? :)

Mikkol
0
 
a_goatCommented:
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
 
Da_WeaselCommented:
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.
0
 
COBOLdinosaurCommented:
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
 
Da_WeaselCommented:
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
 
COBOLdinosaurCommented:
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&

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now