Regular Expression for datetime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?THVpZ2k=?=

    Regular Expression for datetime

    Hi all,
    anyone knows a regular expression for this datetime format?

    dd/MM/yyyy

    Thanks in advance.

    --
    Luigi

  • CreativeMind

    #2
    Re: Regular Expression for datetime

    On May 12, 5:08 pm, Luigi <ciupazNoSpamGr a...@inwind.itw rote:
    Hi all,
    anyone knows a regular expression for this datetime format?
    >
    dd/MM/yyyy
    >
    Thanks in advance.
    >
    --
    Luigi
    Date dd/mm/yyyy
    01/01/1900 through 31/12/2099
    Matches invalid dates such as February 31st

    (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}
    -------------------------------------
    \b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]
    {2}\b

    Comment

    • =?Utf-8?B?THVpZ2k=?=

      #3
      Re: Regular Expression for datetime

      "CreativeMi nd" wrote:
      Date dd/mm/yyyy
      01/01/1900 through 31/12/2099
      Matches invalid dates such as February 31st
      >
      (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}
      -------------------------------------
      \b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]
      {2}\b
      Hi,
      I've tried your regular expression:

      (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}
      \b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]
      {2}\b

      but doesn't work.

      L

      Comment

      • CreativeMind

        #4
        Re: Regular Expression for datetime

        1. (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]
        {2}
        try it again
        On May 12, 6:31 pm, Luigi <ciupazNoSpamGr a...@inwind.itw rote:
        "CreativeMi nd" wrote:
        Date dd/mm/yyyy
        01/01/1900 through 31/12/2099
        Matches invalid dates such as February 31st
        >
        (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}
        -------------------------------------
        \b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]
        {2}\b
        >
        Hi,
        I've tried your regular expression:
        >
        (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}
        \b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]
        {2}\b
        >
        but doesn't work.
        >
        L

        Comment

        • =?Utf-8?B?THVpZ2k=?=

          #5
          Re: Regular Expression for datetime

          "CreativeMi nd" wrote:
          1. (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]
          {2}
          try it again
          This one works:

          (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}

          but accepts also 31/02/2008, that is not correct.

          L

          Comment

          • CreativeMind

            #6
            Re: Regular Expression for datetime

            On May 12, 7:33 pm, Luigi <ciupazNoSpamGr a...@inwind.itw rote:
            "CreativeMi nd" wrote:
            1. (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]
            {2}
            try it again
            >
            This one works:
            >
            (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}
            >
            but accepts also 31/02/2008, that is not correct.
            >
            L
            try this:
            ^(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|
            [2-9]\d)?\d{2}))|((0 ?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-
            \/]((1[6-9]|[2-9]\d)?\d{2}))|((0 ?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]
            ((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?
            (0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))$

            Comment

            • =?Utf-8?B?THVpZ2k=?=

              #7
              Re: Regular Expression for datetime

              "CreativeMi nd" wrote:
              try this:
              ^(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|
              [2-9]\d)?\d{2}))|((0 ?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-
              \/]((1[6-9]|[2-9]\d)?\d{2}))|((0 ?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]
              ((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?
              (0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))$
              >
              This is better ;-)
              Thanks a lot.

              Luigi

              Comment

              Working...