Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to change date format from from MM/DD/YY to DD/MM/YYYY

    General Discussion
    3
    4
    12074
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Yusuf Qureshi
      Yusuf Qureshi last edited by

      I have a data in which I have a dates mentioned in MM/DD/YY which I want to convert it to DD/MM/YYYY, is there a easy way to convert the same.

      1 Reply Last reply Reply Quote 0
      • gerdb42
        gerdb42 last edited by

        The basic approach would be a simple RegEx Search&Replace:

        Search for: (\d{2})/(\d{2})/(\d{2,4})
        Replace with: \2/\1/\3

        Of course this is only a simple rearrangement of digits.

        gerdb42 1 Reply Last reply Reply Quote 0
        • gerdb42
          gerdb42 @gerdb42 last edited by

          Ok, edits only allowed for 180 seconds, so I have to use a reply to self.

          Overlooked the conversion from “YY” to “YYYY”.

          search for : \d{2}/\d{2}/\d{2}
          replace with: \2/\1/20\3

          Works only for Dates in the 2000s, of course.

          1 Reply Last reply Reply Quote 0
          • guy038
            guy038 last edited by guy038

            Hello Yusuf and Gerdb42,

            Gerdb42, I think that, annoyed about waiting 3 minutes to correct your post, your just omit the 3 groups to re-arrange the date :-))

            So, Yusuf, the correct Gerdb42 S/R is, of course :

            SEARCH : (\d{2})/(\d{2})/(\d{2})

            REPLACE : \2/\1/20\3

            Cheers,

            guy038

            P.S. :

            Oh ! Thinking about the 2000’s years, here is an other solution :

            SEARCH : (\d{2})/(\d{2})/(([0-4])\d|[5-9]\d)

            REPLACE : \2/\1/(?{4}20:19)\3

            So, supposing the year, written with TWO digits :

            • If the year is between the 00 and 49 values, we rewrite the string 20, followed by the year value

            • If the year is between the 50 and 99 values, we rewrite the string 19, followed by the year value

            For instance, the two dates :

            12/15/49
            01/15/50
            

            would be changed into :

            15/12/2049
            15/01/1950
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors