Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jscript - Add to Date

Posted on 2003-11-26
8
Medium Priority
?
423 Views
Last Modified: 2008-02-26
Hi

In Jscript how can i add 12 days to todays date and return the full date ie

(26/11/2003 + 12) = 8/12/2003 ???

Thanks
IT
0
Comment
Question by:itimes
[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
  • 4
  • 4
8 Comments
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9826089
<script language="JavaScript"><!--
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

alert(addDays(new Date(),12));
//--></script>

Cheers!!
 
0
 

Author Comment

by:itimes
ID: 9830500
HI

However I need this to be server side ... will this still work what methods will i need to replace ... I understand javascript is similar to jscript but some methods are different .. yes ???

Thnaks for the help ....

IT

0
 

Author Comment

by:itimes
ID: 9830550
Sorry this does work Server side

One more thing and i have uped th points for this :

How can i format a date like the result of the add date so

so i  have "01/08/2003 09:33:23" and wish to convert this to "Thu Nov 27 09:26:14 UTC 2003"

As after iv added to my dates i wish to run checked ie greater than , less than set dates etc ......
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 21

Expert Comment

by:ap_sajith
ID: 9830876
Try this..

<script language="JavaScript"><!--
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

alert(addDays(new Date(),12));

alert(new Date('01/08/2003 09:33:23'));
// new Date (Date Value) coverts the date to UTC Format//
//--></script>

Cheers!!
0
 

Author Comment

by:itimes
ID: 9831492
Thanks works fine however its US date format so (mm/dd/yyyy) is there any way to get the UK format as my date in question is formated (dd/mm/yyyy) ....??
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9831563
Since you are writing the code server side, you could try and set session.LCID=2057 and see if it returns the UK date format. Post your code here If it still doesnt work..

Cheers!!
0
 

Author Comment

by:itimes
ID: 9831691
Still not shwoing UK code below

*********************************

<%@language = jscript %>

<%

var TDate = "";
var TDate1 = "";

Session.LCID=2057

function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}


TDate = addDays(new Date(),14);

TDate1 = new Date('27/11/2003 09:33:23');

%>

Todays date - <%=TDate1%><P>
Plus 14 - <%=TDate%><P>
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 540 total points
ID: 9831909
Try this..

<%@language = jscript %>

<%

var TDate = "";
var TDate1 = "";


function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}


TDate = addDays(new Date(),14);
TDate1 = fmtDate(new Date());

function fmtDate(mydate){
var year=mydate.getYear()
if (year < 1000)
      year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
      daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
      dn="PM"
if (hours>12){
      hours=hours-12
}
if (hours==0)
      hours=12
if (hours<=9)
      hours="0"+hours
if (minutes<=9)
      minutes="0"+minutes
if (seconds<=9)
      seconds="0"+seconds

return  daym+" "+ month +" "+year+ " " +hours+":"+minutes+" "+dn
}

%>

Todays date - <%=TDate1%><P>
Plus 14 - <%=TDate%><P>

Cheers!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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