Input string and date format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    Input string and date format

    I've two input fields in wich the user enter dates.

    I've put something like "enter date here (dd/mm/yyyy) but most of the user
    don't enter date in correct format. So I'd like to be able to get any format
    coming from user as I must put those dates in a MySQL database:
    some format: (non-US format, so day/month/year)

    1/9/2004
    1/09/2004
    01/9/2004
    01/09/2004
    1/9/04
    1/09/04
    01/9/04
    01/09/04
    same with any other separator like '-', space...
    1-9-2004
    1-09-04
    1 10 2004
    ....
    the max input field lenght is 10 characters.
    I must put the entered value in a Mysql date field, so it must be well
    formatted.

    Does it exists any function ?

    Bob


  • Pedro Graca

    #2
    Re: Input string and date format

    Bob Bedford wrote:[color=blue]
    > Does it exists any function ?[/color]
    * that automatically recognizes the date input format and reformats to
    * another format?

    Nope.

    Try making your users enter dates bit-by-bit


    Day: (dropdown list from 1 to 31)
    Month: (dropdown list from January to December)
    Year: (dropdown list from 1901 to <current_year >)

    --
    Mail to my "From:" address is readable by all at http://www.dodgeit.com/
    == ** ## !! ------------------------------------------------ !! ## ** ==
    TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
    may bypass my spam filter. If it does, I may reply from another address!

    Comment

    • Gary L. Burnore

      #3
      Re: Input string and date format

      On 3 Dec 2004 15:35:30 GMT, Pedro Graca <hexkid@dodgeit .com> wrote:
      [color=blue]
      >Bob Bedford wrote:[color=green]
      >> Does it exists any function ?[/color]
      >* that automatically recognizes the date input format and reformats to
      >* another format?
      >
      >Nope.
      >
      >Try making your users enter dates bit-by-bit
      >
      >
      > Day: (dropdown list from 1 to 31)
      > Month: (dropdown list from January to December)
      > Year: (dropdown list from 1901 to <current_year >)[/color]

      Which, unless you implement javascript or something similar, would
      allow for such dates as 31 Feb, 2004


      --
      gburnore@databa six dot com
      ---------------------------------------------------------------------------
      How you look depends on where you go.
      ---------------------------------------------------------------------------
      Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
      | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
      DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
      | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
      Black Helicopter Repair Svcs Division | Official Proof of Purchase
      =============== =============== =============== =============== ===============
      Want one? GET one! http://signup.databasix.com
      =============== =============== =============== =============== ===============

      Comment

      • Bob Bedford

        #4
        Re: Input string and date format

        "Gary L. Burnore" <gburnore@datab asix.com> a écrit dans le message de news:
        coq1dg$l4f$8@bl ackhelicopter.d atabasix.com...[color=blue]
        > On 3 Dec 2004 15:35:30 GMT, Pedro Graca <hexkid@dodgeit .com> wrote:
        >[color=green]
        >>Bob Bedford wrote:[color=darkred]
        >>> Does it exists any function ?[/color]
        >>* that automatically recognizes the date input format and reformats to
        >>* another format?
        >>
        >>Nope.
        >>
        >>Try making your users enter dates bit-by-bit
        >>
        >>
        >> Day: (dropdown list from 1 to 31)
        >> Month: (dropdown list from January to December)
        >> Year: (dropdown list from 1901 to <current_year >)[/color]
        >
        > Which, unless you implement javascript or something similar, would
        > allow for such dates as 31 Feb, 2004[/color]

        I would have said I want absolutely avoid such entry type. I (and most
        users) hate such entry type, also because all other fields close to them are
        keyboard entries, I want to avoid the keyboard-mouse-keyboard-mouse fields
        (even if people may use keyboard on dropdown, most don't know you can). it
        must be keyboard entry.

        Bob


        Comment

        • Pedro Graca

          #5
          Re: Input string and date format

          Gary L Burnore wrote:[color=blue]
          > On 3 Dec 2004 15:35:30 GMT, Pedro Graca <hexkid@dodgeit .com> wrote:[color=green]
          >>
          >>Try making your users enter dates bit-by-bit
          >>
          >>
          >> Day: (dropdown list from 1 to 31)
          >> Month: (dropdown list from January to December)
          >> Year: (dropdown list from 1901 to <current_year >)[/color]
          >
          > Which, unless you implement javascript or something similar, would
          > allow for such dates as 31 Feb, 2004[/color]

          Yes. Better than making the users submit year and month on one screen
          and the day on the next screen.

          Anyway:

          php$ php -r écho date("Y-m-d", mktime(0, 0, 0, 2, 31, 2004));'
          2004-03-02

          If they try 31 Feb, 2004 they'll get 2 Mar, 2004 :-)
          --
          Mail to my "From:" address is readable by all at http://www.dodgeit.com/
          == ** ## !! ------------------------------------------------ !! ## ** ==
          TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
          may bypass my spam filter. If it does, I may reply from another address!

          Comment

          • Michael Fesser

            #6
            Re: Input string and date format

            .oO(Bob Bedford)
            [color=blue]
            >I've put something like "enter date here (dd/mm/yyyy) but most of the user
            >don't enter date in correct format. So I'd like to be able to get any format
            >coming from user as I must put those dates in a MySQL database:
            >some format: (non-US format, so day/month/year)[/color]

            If it's always d/m/y just with different separators it should be quite
            easy to do with a regular expression, something like

            $pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{1,2}|\d{4}) $#';
            preg_match($pat tern, $date, $result);

            After splitting use checkdate() to see if the entered date is valid.

            Micha

            Comment

            • Michael Fesser

              #7
              Re: Input string and date format

              .oO(Pedro Graca)
              [color=blue]
              >Try making your users enter dates bit-by-bit
              >
              > Day: (dropdown list from 1 to 31)
              > Month: (dropdown list from January to December)
              > Year: (dropdown list from 1901 to <current_year >)[/color]

              One of the worst things you can do in terms of usability.

              Micha

              Comment

              • Tony Marston

                #8
                Re: Input string and date format

                Take a look at http://www.tonymarston.co.uk/php-mysql/dateclass.html

                --
                Tony Marston

                This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



                "Bob Bedford" <bedford1@YouKn owWhatToDoHereh otmail.com> wrote in message
                news:41b0816a$0 $5643$5402220f@ news.sunrise.ch ...[color=blue]
                > I've two input fields in wich the user enter dates.
                >
                > I've put something like "enter date here (dd/mm/yyyy) but most of the user
                > don't enter date in correct format. So I'd like to be able to get any
                > format coming from user as I must put those dates in a MySQL database:
                > some format: (non-US format, so day/month/year)
                >
                > 1/9/2004
                > 1/09/2004
                > 01/9/2004
                > 01/09/2004
                > 1/9/04
                > 1/09/04
                > 01/9/04
                > 01/09/04
                > same with any other separator like '-', space...
                > 1-9-2004
                > 1-09-04
                > 1 10 2004
                > ...
                > the max input field lenght is 10 characters.
                > I must put the entered value in a Mysql date field, so it must be well
                > formatted.
                >
                > Does it exists any function ?
                >
                > Bob
                >[/color]


                Comment

                • Bob Bedford

                  #9
                  Re: Input string and date format

                  Hi Michael
                  [color=blue]
                  > $pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{1,2}|\d{4}) $#';
                  > preg_match($pat tern, $date, $result);
                  >[/color]
                  I've to store the value in a MySQL database, so I've to get correct format.

                  Thanks for your help, Tony Marston gave an excellent tutorial and full code
                  for what I wanted to do.

                  Cheers.


                  Comment

                  • Bob Bedford

                    #10
                    Re: Input string and date format


                    "Tony Marston" <tony@NOSPAM.de mon.co.uk> a écrit dans le message de news:
                    coqacv$889$1$83 02bc10@news.dem on.co.uk...[color=blue]
                    > Take a look at http://www.tonymarston.co.uk/php-mysql/dateclass.html
                    >
                    > --
                    > Tony Marston
                    >
                    > http://www.tonymarston.net[/color]

                    Great, thanks for your help. I've bookmarked your site ;-)

                    Cheers


                    Comment

                    • Michael Fesser

                      #11
                      Re: Input string and date format

                      .oO(Bob Bedford)
                      [color=blue][color=green]
                      >> $pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{1,2}|\d{4}) $#';
                      >> preg_match($pat tern, $date, $result);
                      >>[/color]
                      >I've to store the value in a MySQL database, so I've to get correct format.[/color]

                      Sure. The above code was just for splitting a submitted date. If you
                      have separate values for day, month and year it's a quite simple task to
                      check the date and to create a yyyy-mm-dd string.
                      [color=blue]
                      >Thanks for your help, Tony Marston gave an excellent tutorial and full code
                      >for what I wanted to do.[/color]

                      OK.

                      Micha

                      Comment

                      Working...