Solved

Jscript - Add to Date

Posted on 2003-11-26
8
422 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 135 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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