Solved

Jscript - Add to Date

Posted on 2003-11-26
8
419 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
  • 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
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!

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

713 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