Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Javascript - Display future expiration date in short format

    I'm trying to find a way to display a future date in short format (as an expiration date) with Javascript. I've figured out how to do it with long format, but have no idea how to convert it and I'm not great with Javascript.

    Here is code that I found on another forum and modified:

    Code:
    <!doctype html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    
    <!doctype html>
    <head>
    <title>Expires</title>
    </head>
    <body>
    
    <script>
    
    var myDelayInDays=6, myDate=new Date();
    myDate.setDate(myDate.getDate()+myDelayInDays);
    
    document.write('Expires: ' + myDate.toLocaleDateString());
    
    </script>
    </body>
    </html>
    
    </body>
    </html>
    Which displays:

    "Expires: Monday, May 21, 2012"

    I would like it to display:

    "Expires: 05/21/2012"

    Can anyone help?!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    Code:
    var myDelayInDays=6, myDate=new Date();
    myDate.setDate(myDate.getDate()+myDelayInDays);
    var mn = myDate.getMonth()+1;
    var dy = myDate.getDate();
    var shortDate = ( mn < 10 ? "0" : "" ) + mn + "/" + ( dy < 10 ? "0" : "" ) + dy + "/" + myDate.getFullYear();
    
    document.write('Expires: ' + shortDate);
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    MY HERO! Thanks so much!!


  •  

    LinkBacks (?)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •