Solved

Jscript - Add to Date

Posted on 2003-11-26
8
412 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now