Solved

# Format Date Time In ASP.... :-)

Posted on 2003-02-27
Medium Priority
165 Views
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
Question by:Azurden
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2
• 2
• +3

LVL 9

Expert Comment

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

LVL 3

Expert Comment

ID: 8036098
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

LVL 14

Expert Comment

ID: 8036107
Date + 3 * 365
0

LVL 2

Accepted Solution

mikkolsoft earned 100 total points
ID: 8036190
a_goat: should be

and

right? :)

Mikkol
0

LVL 3

Expert Comment

ID: 8036436
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

LVL 3

Expert Comment

ID: 8048581
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

LVL 53

Expert Comment

ID: 9115207
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

LVL 3

Expert Comment

ID: 9169922
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

LVL 53

Expert Comment

ID: 9306236
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,

Cd&

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logiâ€¦
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get â€¦
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arrâ€¦
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
###### Suggested Courses
Course of the Month12 days, left to enroll