Need help to remove list of days from date script

Discussion in 'Javascript' started by mistral, Jun 7, 2006.

  1. mistral

    mistral Guest

    Need help to remove list of days from date script. Need format "June
    07, 2006"


    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin

    // Get today's current date.
    var now = new Date();

    // Array list of days.
    var days = new
    Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

    // Array list of months.
    var months = new
    Array('January','February','March','April','May','June','July','August','September','October','November','December');

    // Calculate the number of the current day in the week.
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

    // Calculate four digit year.
    function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;
    }

    // Join it all together
    today = days[now.getDay()] + ", " +
    months[now.getMonth()] + " " +
    date + ", " +
    (fourdigits(now.getYear())) ;

    // Print out the data.
    document.write(today);

    // End -->
    </script>


    thanks.
    Mistral
    mistral, Jun 7, 2006
    #1
    1. Advertising

  2. mistral

    RobG Guest

    mistral wrote:
    > Need help to remove list of days from date script. Need format "June
    > 07, 2006"


    Some ideas below...


    > <SCRIPT LANGUAGE="JavaScript">


    The language attribute is deprecated, type is required:

    <script type="text/javascript">


    > <!-- Begin


    Do not use HTML comments inside script elements, it is completely
    unnecessary and may be harmful in some circumstances.


    > // Get today's current date.
    > var now = new Date();


    That creates a date object that can be used to get the date at the time
    the object was created.


    > // Array list of days.
    > var days = new
    > Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');


    Apparently you don't want this array, so just deleted it.


    > // Array list of months.
    > var months = new
    > Array('January','February','March','April','May','June','July','August','September','October','November','December');


    It can be simpler to initialise the months array with an "initialiser":

    var months = ['January', 'February', 'March', 'April',
    'May', 'June', 'July', 'August',
    'September', 'October', 'November', 'December'];


    > // Calculate the number of the current day in the week.
    > var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();


    That gets the date, not the day number. To get a 2 digit date as a
    string, you could use:

    var now = new Date();
    var nowDate = now.getDate();
    nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;


    I think it's not a good idea to have a variable called 'date' when there
    is a Date object (not critical, just a preference).


    > // Calculate four digit year.
    > function fourdigits(number) {
    > return (number < 1000) ? number + 1900 : number;


    Or just:

    var year = now.getFullYear();

    getFullYear() is not supported by some old browsers (IE 4 at least I
    think), you may need to add some feature detection or fall-back.


    > // Join it all together
    > today = days[now.getDay()] + ", " +
    > months[now.getMonth()] + " " +
    > date + ", " +
    > (fourdigits(now.getYear())) ;


    If you aren't going to re-use the date string, write it directly:

    document.write(
    months[now.getMonth()] + ' ' + nowDate + ', ' + year
    );


    [...]


    --
    Rob
    RobG, Jun 7, 2006
    #2
    1. Advertising

  3. mistral

    mistral Guest

    RobG пиÑал(а):

    > mistral wrote:
    > Need help to remove list of days from date script. Need format "June
    > 07, 2006"


    > Some ideas below...



    <SCRIPT LANGUAGE="JavaScript">

    The language attribute is deprecated, type is required:

    <script type="text/javascript">


    <!-- Begin

    Do not use HTML comments inside script elements, it is completely
    unnecessary and may be harmful in some circumstances.


    // Get today's current date.
    var now = new Date();

    That creates a date object that can be used to get the date at the
    time
    the object was created.


    // Array list of days.
    var days = new

    Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

    Apparently you don't want this array, so just deleted it.


    // Array list of months.
    var months = new

    Array('January','February','March','April','May','June','July','August','September','October','November','December');

    It can be simpler to initialise the months array with an
    "initialiser":

    var months = ['January', 'February', 'March', 'April',
    'May', 'June', 'July', 'August',
    'September', 'October', 'November', 'December'];


    // Calculate the number of the current day in the week.
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

    That gets the date, not the day number. To get a 2 digit date as a
    string, you could use:

    var now = new Date();
    var nowDate = now.getDate();
    nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;


    I think it's not a good idea to have a variable called 'date' when
    there
    is a Date object (not critical, just a preference).


    // Calculate four digit year.
    function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;

    Or just:

    var year = now.getFullYear();

    getFullYear() is not supported by some old browsers (IE 4 at least I
    think), you may need to add some feature detection or fall-back.


    // Join it all together
    today = days[now.getDay()] + ", " +
    months[now.getMonth()] + " " +
    date + ", " +
    (fourdigits(now.getYear())) ;

    If you aren't going to re-use the date string, write it directly:

    document.write(
    months[now.getMonth()] + ' ' + nowDate + ', ' + year
    );

    [...]

    Rob
    --------------------------------------------
    Hi,

    I tried implement this ideas as follows, but script not work at all:

    <script type="text/javascript">

    var now = new Date();

    var months = ['January', 'February', 'March', 'April',
    'May', 'June', 'July', 'August', 'September', 'October',
    'November', 'December'];

    var now = new Date();

    var nowDate = now.getDate();

    nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;

    function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;

    document.write(
    months[now.getMonth()] + ' ' + nowDate + ', ' + year
    );

    </script>
    mistral, Jun 7, 2006
    #3
  4. JRS: In article <>
    , dated Wed, 7 Jun 2006 09:22:38 remote, seen in
    news:comp.lang.javascript, mistral <> posted :

    Please find out how to quote.

    > // Calculate four digit year.
    > function fourdigits(number) {
    > return (number < 1000) ? number + 1900 : number;


    Missing }

    > Or just:
    >
    > var year = now.getFullYear();
    >
    > getFullYear() is not supported by some old browsers (IE 4 at least I
    > think), you may need to add some feature detection or fall-back.


    It is supported in IE4 as supplied with Win98 first UK release.



    >I tried implement this ideas as follows, but script not work at all:
    >
    ><script type="text/javascript">
    >
    >var now = new Date();


    Superfluous.

    >
    >var months = ['January', 'February', 'March', 'April',
    > 'May', 'June', 'July', 'August', 'September', 'October',
    > 'November', 'December'];
    >
    >var now = new Date();
    >
    >var nowDate = now.getDate();
    >
    >nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;
    >
    >function fourdigits(number) {
    > return (number < 1000) ? number + 1900 : number;


    Needs trailing }
    That fourdigits will fail in browsers in which getYear() returns
    year%100; it's been said that such browsers exist(ed).

    function fourdigits(number) { return 2000 + number%100 }
    // should, for current date, suffice for all but the youngest
    programmer.


    Needs
    year = fourdigits(now.getYear())
    or
    year = now.getFullYear()
    or
    year = getFY(now)

    >
    >document.write(
    > months[now.getMonth()] + ' ' + nowDate + ', ' + year
    >);
    >
    ></script>


    Read the newsgroup FAQ; see below.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Jun 7, 2006
    #4
  5. mistral

    mistral Guest

    I there some expert which can show how should look full correct
    javascript for current date, that works normally(IE, Firefox, Netscape)
    ? Not comments, but full correct javascript.

    mistral
    mistral, Jun 8, 2006
    #5
  6. JRS: In article <>
    , dated Thu, 8 Jun 2006 05:04:52 remote, seen in
    news:comp.lang.javascript, mistral <> posted :
    >I there some expert which can show how should look full correct
    >javascript for current date, that works normally(IE, Firefox, Netscape)
    >? Not comments, but full correct javascript.



    Yes.

    But, as you have ignored previous advice, experts may now ignore you.

    Note, however, that Merkins often use a format, known as FFF, which
    conflicts both with common sense and with the applicable international
    standard.

    --
    © John Stockton, Surrey, UK. yyww merlyn demon co uk Turnpike v4.00 MIME ©
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
    Dr John Stockton, Jun 8, 2006
    #6
  7. mistral

    Randy Webb Guest

    Dr John Stockton said the following on 6/8/2006 4:52 PM:
    > JRS: In article <>
    > , dated Thu, 8 Jun 2006 05:04:52 remote, seen in
    > news:comp.lang.javascript, mistral <> posted :
    >> I there some expert which can show how should look full correct
    >> javascript for current date, that works normally(IE, Firefox, Netscape)
    >> ? Not comments, but full correct javascript.

    > Yes.
    > But, as you have ignored previous advice, experts may now ignore you.


    If you ignored half the posts you reply to with your pedantic garbage,
    you wouldn't be half as bad.

    > Note, however, that Merkins often use a format, known as FFF, which
    > conflicts both with common sense and with the applicable international
    > standard.


    Your pedantic stupidity never ceases to amaze me.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Jun 9, 2006
    #7
  8. mistral

    mistral Guest

    > Dr John Stockton said the following on 6/8/2006 4:52 PM:

    I there some expert which can show how should look full correct
    javascript for current date, that works normally(IE, Firefox, Netscape)
    ? Not comments, but full correct javascript.
    Yes.


    > But, as you have ignored previous advice, experts may now ignore you.


    > If you ignored half the posts you reply to with your pedantic garbage,
    > you wouldn't be half as bad.


    > Note, however, that Merkins often use a format, known as FFF, which
    > conflicts both with common sense and with the applicable international
    > standard.


    > Your pedantic stupidity never ceases to amaze me.


    > Randy

    ============================
    "But, as you have ignored previous advice, experts may now ignore you."

    I not ingnored previous advice, I DONT UNDERSTAND IT. If you javascript
    exprert, can you you show *full and correct code snippet*? Not
    comments, not abstract Usenet discussion -I dont understand it (and
    your english), but human readable code snippet, ready for use in html
    page?
    mistral, Jun 9, 2006
    #8
  9. JRS: In article <>,
    dated Fri, 9 Jun 2006 03:04:23 remote, seen in
    news:comp.lang.javascript, mistral <> posted :
    >"But, as you have ignored previous advice, experts may now ignore you."
    >
    >I not ingnored previous advice, I DONT UNDERSTAND IT.



    Which parts of "Please find out how to quote." and "Read the newsgroup
    FAQ; see below." did you fail to understand?

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Jun 9, 2006
    #9
  10. mistral

    mistral Guest

    Dr John Stockton пиÑал(а):

    JRS: In article
    <>,
    dated Fri, 9 Jun 2006 03:04:23 remote, seen in
    news:comp.lang.javascript, mistral <> posted :
    "But, as you have ignored previous advice, experts may now ignore you."

    >I not ingnored previous advice, I DONT UNDERSTAND IT.


    > Which parts of "Please find out how to quote." and "Read the newsgroup
    > FAQ; see below." did you fail to understand?



    > © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00IE 4 ©
    > <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    > <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    > <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    ===============================

    I dont understand your expert advice - at all. Sorry.

    Mistral
    mistral, Jun 12, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Stockwell
    Replies:
    2
    Views:
    691
    Anna Martelli Ravenscroft
    Sep 20, 2004
  2. Gerrit
    Replies:
    0
    Views:
    381
    Gerrit
    Sep 20, 2004
  3. Terry Reedy
    Replies:
    0
    Views:
    420
    Terry Reedy
    Sep 20, 2004
  4. Replies:
    5
    Views:
    458
    Bo Yang
    Nov 2, 2006
  5. kirke

    list of days between two days

    kirke, Oct 19, 2006, in forum: Javascript
    Replies:
    7
    Views:
    132
    Julian Turner
    Oct 20, 2006
Loading...

Share This Page