|
Question : Reformat badly recognised MDY dates as DMY
|
|
Ok, I have a solution for the following, but it's clunky as hell! I'm wondering if you guys can come up with some more elegant solutions..
Down here in Australia, the default date format is d/mm/yyyy (hereafter referred to as 'DMY'). We like it that way too. However given that there's a lot of American software around the place, we can sometimes run into problems created by developers who failed to think about dates at the global level.
We have a database system that can (and does!) export data to Excel. The system options are set to use our DMY date format and that works nicely most of the time. However, it appears to us that the systems Export-To-Excel routine doesn't observe the date format in program options and so the resultant Excel sheets are riddled with database-default, American-style MDY dates.
Now Excel certainly does diligently observe our Windows regional settings. It therefore recognises data as a date as long as (in our case), it conforms to the DMY format. Well these dates don't ever do that.
What we end up with in Excel (2k3) is a mix of incorrectly recognised dates with the day and month transposed (this is for dates earlier than the 13th of the month), and unrecognised, plain text data for all the rest. My challenges are a) to convice the DBMS developers that their export function is broken and b) to provide a workaround until that export function is fixed.
Happily, step B is done. I'm sure you'll agree it's not exceedingly difficult, but the way I tackled it sure looks complicated. I'm attempting to instruct some less formula-savvy users how they can deal with these date issues, and I have no doubt that they'll run a mile as soon as they see my mile-long solution. Here's my approach.
Prerequisite: Windows regional settings set to English: Australian, or any region that uses a DMY date format. You could just set a custom date format in there and leave your region alone, too. In this case, be sure to use forward slashes as delimiters or you'll break my formulae.
Column A: All of the days of January 2006, hand entered in ascending order in the format m/d/yyyy. Excel will render the first 12 as dates and the rest as text.
Column B: Calculates the day number with the formula:
=IF(ISERROR(MONTH(A1)),VALUE(MID(A1,FIND("/",A1)+1,FIND("/",A1,FIND("/",A1)+1)-FIND("/",A1)-1)),MONTH(A1))
Column C: Calculates the month number in the same way:
=IF(ISERROR(DAY(A1)),VALUE(MID(A1,1,FIND("/",A1)-1)),DAY(A1))
Column D: Calculates the year:
=IF(ISERROR(YEAR(A1)),VALUE(MID(A1,FIND("/",A1,FIND("/",A1)+1)+1,LEN(A1)-FIND("/",A1,FIND("/",A1)+1))),YEAR(A1))
Column E: Combines B, C and D into a properly formatted and correct date:
=DATE(D1,C1,B1)
Column F: The all-in-one solution. Combine forulae from the previous four columns into one newbie-frightening monster:
=DATE(IF(ISERROR(YEAR(A1)),VALUE(MID(A1,FIND("/",A1,FIND("/",A1)+1)+1,LEN(A1)-FIND("/",A1,FIND("/",A1)+1))),YEAR(A1)),IF(ISERROR(DAY(A1)),VALUE(MID(A1,1,FIND("/",A1)-1)),DAY(A1)),IF(ISERROR(MONTH(A1)),VALUE(MID(A1,FIND("/",A1)+1,FIND("/",A1,FIND("/",A1)+1)-FIND("/",A1)-1)),MONTH(A1)))
Of course it works, and works pretty well. But I'm sure I just travelled from Sydney to Melbourne via London. Simpler solutions, anyone?
TIA, Tim
|
|
Answer : Reformat badly recognised MDY dates as DMY
|
|
Making some assumptions... try the following formula...
=IF(ISERROR(YEAR(A1)),IF(MID(A1,2,1)="/",DATE(MID(A1,6,4),MID(A1,1,1),MID(A1,3,2)),DATE(MID(A1,7,4),MID(A1,1,2),MID(A1,4,2))),DATE(YEAR(A1),DAY(A1),MONTH(A1)))
UP TO YOU to decide if it is easier/simpler solution ... explanation to follow...
Tony
|
|
|
|