Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date formating

Status
Not open for further replies.

spicymango

Programmer
May 25, 2008
119
CA
Hi,

I want to subtract 12 months from the current date and get the result in this format(6/26/2008).
How can i do that following gives me date in different format. I will appreciate your help.


Code:
<script>
var today       =new Date();
 
var ten_days_ago=new Date().setDate(today.getDate()-365);
var startDate= new Date(ten_days_ago);
alert(startDate);

</script>
 
[tt]startDate_formatted=(startDate.getMonth()+1) + "/" + startDate.getDate() + "/" +startDate.getFullYear();[/tt]
 
thanks for your reply, I actually also wanted to subtract 12 months as well from the current date. I got this code, it work fine, but on Fire FOx it give me year 107, instead 2007, don't know why it does that on FireFox, works fine IE.

Code:
<script>
function year_before(s) {
    // parse s for month, day, year
    var dateArray = s.split('/');
    sdate = new Date(dateArray[2],dateArray[0]-1,dateArray[1]);
// figure out day, month, year  ago
    var odate = new Date(sdate.getTime() - (365 * 86400000));
// return value
    return (odate.getMonth()+1) + '/' + odate.getDate() + '/' + odate.getYear();
}
var year_ago = year_before("06/02/2008");
alert( year_ago);
</script>

</script>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top