?
Solved

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

Posted on 2003-02-27
9
Medium Priority
?
165 Views
Last Modified: 2010-04-06
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8035630
or you could convert to yyyymmdd , add 30000, convert it back
0
 
LVL 3

Expert Comment

by:a_goat
ID: 8036098
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
 
LVL 14

Expert Comment

by:aelatik
ID: 8036107
Date + 3 * 365
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 2

Accepted Solution

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

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

right? :)

Mikkol
0
 
LVL 3

Expert Comment

by:a_goat
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

by:Da_Weasel
ID: 8048581
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
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

by:Da_Weasel
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

by:COBOLdinosaur
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,
please leave a comment for the mods.

Cd&

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question