get/format date field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • peashoe@yahoo.com

    get/format date field

    I have an asp page that uses a calendar.js (pop-up) file to add an
    exact date format in the text field (txtDDate). My problem is I need
    some javascript that sets an alert that does not allow them to select
    today.

    example:
    var dtToday = Date()
    if(document.frm Software.txtDDa te.value == dtToday)
    {
    alert("You cannot select same day distributions. Please enter a new
    value in the \"Delivery Date\" field.");
    return false
    }

    But dtToday is blank....How can I get dtToday value? Also, when I set
    the dtToday value outside javascript and used a Response.Write to see
    what format Date() came up with - it gave me 1/24/2005 - but the
    calendar pop-up gives me 01/24/2005....could this also be the issue?
    Thanks is advance!
    Lisa

  • BMR

    #2
    Re: get/format date field

    You should format dtToday with Date methods ie dtToday.toLocal eString()
    or rather with getDate(), getMonth() and getFullYear(). Because when you
    write dtToday, in fact it writes dtToday.toStrin g(), which is "Mon Jan
    24 17:06:17 2005" (my local time). dtToday is an object, not a variable.

    BMR

    peashoe@yahoo.c om a écrit :[color=blue]
    > I have an asp page that uses a calendar.js (pop-up) file to add an
    > exact date format in the text field (txtDDate). My problem is I need
    > some javascript that sets an alert that does not allow them to select
    > today.
    >
    > example:
    > var dtToday = Date()
    > if(document.frm Software.txtDDa te.value == dtToday)
    > {
    > alert("You cannot select same day distributions. Please enter a new
    > value in the \"Delivery Date\" field.");
    > return false
    > }
    >
    > But dtToday is blank....How can I get dtToday value? Also, when I set
    > the dtToday value outside javascript and used a Response.Write to see
    > what format Date() came up with - it gave me 1/24/2005 - but the
    > calendar pop-up gives me 01/24/2005....could this also be the issue?
    > Thanks is advance!
    > Lisa
    >[/color]

    Comment

    • Dr John Stockton

      #3
      Re: get/format date field

      JRS: In article <1106573221.344 153.6140@z14g20 00cwz.googlegro ups.com>,
      dated Mon, 24 Jan 2005 05:27:01, seen in news:comp.lang. javascript,
      peashoe@yahoo.c om posted :[color=blue]
      >I have an asp page that uses a calendar.js (pop-up) file to add an
      >exact date format in the text field (txtDDate). My problem is I need
      >some javascript that sets an alert that does not allow them to select
      >today.
      >
      >example:
      >var dtToday = Date()[/color]

      Should be new Date() ; or at least that usually would be used.
      In my browser, Date() gives a string unequal to that given by using
      new Date().toString () . Date() ignores its parameter.

      Both of them give date-and-time.
      [color=blue]
      >if(document.fr mSoftware.txtDD ate.value == dtToday)[/color]

      The left side is a string as entered by the user, who *may* have used
      the format that you expect.
      [color=blue]
      >{
      >alert("You cannot select same day distributions. Please enter a new
      >value in the \"Delivery Date\" field.");[/color]

      Code should be indented to show intended structure.
      In News, code lines should NOT be broken by the sending agent;
      transmitted code should be executable directly. Better for you to do it
      right than to have all your readers trying to repair the damage.
      [color=blue]
      >return false
      >}
      >
      >But dtToday is blank....How can I get dtToday value?[/color]

      Perhaps your system interprets Date() differently.
      [color=blue]
      >Also, when I set
      >the dtToday value outside javascript and used a Response.Write to see
      >what format Date() came up with - it gave me 1/24/2005 - but the
      >calendar pop-up gives me 01/24/2005....could this also be the issue?[/color]

      Even though those are FFF, that is not the main issue; merely a residual
      future cause of failure.

      ISTM that you are asking to ensure that the requested date is not today.
      But why? Very probably you want it to be after today, so disallowing
      today-or-before.

      If you check that the requested date is a valid date, preferably as
      YYYY-MM-DD but in FFF if you must, then you can read it into a Date
      Object and it will mean 00:00:00 local of the date in question. If it
      were any earlier than 00:00:00 tomorrow, it would be 00:00:00 today or
      earlier, i.e. before the current moment. You can therefore compare
      new Date().valueOf( ) < new Date(userdata). valueOf()
      if you are confident that the user format (after validation) is read
      correctly in whatever localisation your system has; or
      new Date().valueOf( ) < new Date(Y, M, D).valueOf()
      with Y M D (or +Y +M +D) being generated during validation.


      To check that a date is equal to another date, you must remove the time
      components. Those blessed enough to be using GMT can use
      (new Date()/864e5)|0 == (new Date(Y, M, D)/864e5)|0
      but others will need to extract Y M D from each and use either
      Y1==Y2 && M1==M2 && D1==D2
      or as
      (Y1*100+M1)*100 +D1 == (Y2*100+M2)*100 +D2



      Read the newsgroup FAQ; see below.

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

      Comment

      • peashoe

        #4
        Re: get/format date field

        John,
        Thanks for the reply 'except for the indent comment' Not sure why you
        would make that remark because you know google groups formats what you
        paste to whatever it feels like.

        In any case, I went another route and updated my calendar.js file to
        not accept same day selection.

        I will keep this chunk of info for future reference though
        Thanks again

        ~L~

        Comment

        • Dr John Stockton

          #5
          Re: get/format date field

          JRS: In article <1106679053.368 468.112450@f14g 2000cwb.googleg roups.com>
          , dated Tue, 25 Jan 2005 10:50:53, seen in news:comp.lang. javascript,
          peashoe <peashoe@yahoo. com> posted :
          [color=blue]
          >Thanks for the reply 'except for the indent comment' Not sure why you
          >would make that remark because you know google groups formats what you
          >paste to whatever it feels like.[/color]

          You chose to use Google, when you could have chosen a proper newsreader
          or a different, better-designed Web service. The responsibility is
          yours; you do not yet live in a world-wide dictatorship forcing use of
          Google.

          Code should be indented to show the intended meaning; it is unreasonable
          to expect others to fathom out the intended structure - which is not
          necessarily the actual structure - of badly-presented material.

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

          Comment

          Working...