0

Suppose I have a date (e.g 10-1-2017), and I know the following constants:

  1. The first two digits will always be the day
  2. The separator (sep) will always be one of / and -
  3. The date will always be formatted like so: dd(sep)M(sep)y or dd(sep)y(sep)M where:

    • M could be any month format (M, MM, ...) and
    • y could be any year format (y, yy, yyy, yyyy ...)

How do I decipher the format for a given date?

airudah
  • 1,169
  • 12
  • 19
Rjj
  • 249
  • 1
  • 7
  • 22
  • 1
    This would be difficult to tell. You should already know the expected date format. For instance, how do you decide from your example date that it is the 10th of January or 1st of October? This might provide some inspiration to solve your problem: https://stackoverflow.com/questions/7579227/how-to-get-the-given-date-string-formatpattern-in-java – airudah Nov 14 '17 at 10:43
  • Hi Robert, Thanks for your reply. for your question 'For instance, how do you decide from your example date that it is the 10th of January or 1st of October?' ..we always have first 2 digits represents day from the date and now any which case I can decode second parameter either month or year. Based on this is it possible to know the incoming date is separated by /, . or - ? – Rjj Nov 14 '17 at 11:21
  • 1
    Well in that case, If you're certain the first two digits will always be the days, then you could build a sequence of possible formats that meet your known date criteria (i.e. first two digits and separator), and build some logic to try and parse a given date through each one till you find a match. The post I referenced above has a similar logic in Java.. – airudah Nov 14 '17 at 11:38
  • I've heavily edited the question so it's clearer what you're asking, should someone want to take a stab at a solution. – airudah Nov 14 '17 at 22:54

0 Answers0