Link to home
Start Free TrialLog in
Avatar of itimes
itimes

asked on

Jscript - Add to Date

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
Avatar of ap_sajith
ap_sajith

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

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

Cheers!!
 
Avatar of itimes

ASKER

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

Avatar of itimes

ASKER

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 ......
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!!
Avatar of itimes

ASKER

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) ....??
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!!
Avatar of itimes

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of ap_sajith
ap_sajith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial