Results 1 to 5 of 5

Thread: Date Format Issue

  1. #1
    Join Date
    Jan 2013

    Date Format Issue

    Newbie here with what's probably a very simple question for you folks but I would greatly appreciate any help.

    I'm using a javascript to automatically add 5 days to today's date. It works just fine but it displays the date as "Friday, February 01, 2013" when I would like it displayed as just "February 01" (i.e. without the day of the week or the year).

    Here's the script I'm using and thanks in advance for any suggestions!

    function addDate(dateObject, numDays) {
    dateObject.setDate(dateObject.getDate() + numDays);
    return dateObject.toLocaleDateString();
    var numDays;
    var oldDate;
    var newDate;
    oldDate = new Date();
    numDays = 5;
    <!-- document.write(""); -->
    newDate = addDate(oldDate, numDays)
    document.writeln("<small><font color='000000' face='Arial'><b>" + newDate + "</b></font></small>");

  2. #2
    Join Date
    Aug 2008
    Use the getDate and getMonth methods to get the date and month respectively:

    var monthNames = ["January", "February", "March",
        "April", "May", "June", "July", "August", "September",
        "October", "November", "December"];
    var date = new Date();
    var currentDate = date.getDate();
    var currentMonth = date.getMonth();
    alert( monthNames[currentMonth] + " " + currentDate );
    So instead of returning dateObject.toLocaleDateString() from addDate you would return monthNames[dateObject.getMonth()] + " " + dateObject.getDate()
    Last edited by ReFreezed; 01-28-2013 at 01:42 PM.

  3. #3
    Join Date
    Jan 2013
    Thanks for the response ReFreezed. It sort of worked in that it displayed the result as just the month and date but it did so in an alert box as opposed to on the web page (the document.write thing). Also, it just displayed today's date and not today's date plus 5 days which is what the script is all about.

  4. #4
    Join Date
    Aug 2012
    By the way ..........

    A summary of the international standard date and time notation - International Standard ISO 8601

    Web Developer Tool Kit - for creating Standards compliant and Interoperable web pages
    W3C Markup Validation Service - validate HTML code for reliable rendering in all Browsers
    WAVE accessibility evaluation tool - check page structure, image alt text, form labels, etc.

  5. #5
    Join Date
    Jan 2013
    Thank you polyglot, but this script is for use on a US site that only sells product to people in the US.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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