Dates Exported to Spreadsheets Misbehave
Posted: 14 Sep 2010 21:58
I have many Query Result Sets that contain a Date column.
These may be exported using Query Menu > Save Query Result Set As > Comma-Separated CSV File.
The CSV file can be opened with Excel but the Date column is displayed oddly.
See later spreadsheet image for examples.
Some Dates left-justify in column and display in Formula Bar as 7 November 1845.
Other Dates right-justify in column as 09-May-14 and in Formula Bar as 09/05/1914.
A Google search reveals that Excel and other Spreadsheets do not recognise dates before 1 Jan 1900 and treat them as text!!!
Any attempt to Format Cells as Date does not help.
Any attempt to Format Cells as Text results in the right-justified dates becoming large integers!
The only technique that helps, is to force each Query Result Date to be a text string in Excel by prefixing each date with an apostrophe ( ' ).
For example define the Query Column Date as =Text('' ' . %INDI.BIRT.DATE%).
However, in all the above cases it is impossible to Sort the Excel column of Dates into date order.
Therefore, you are forced to accept the sort order supplied by the FH Query.
Example Excel Spreadsheet of Exported Dates:

Maybe the =DayNumber(%date%) Function would supply an integer for the %date% that could act as a sort column.
Unfortunately, it only supplies an integer for a limited subset of FH date formats, where Day & Month & Year are all defined.
Maybe the =Timespan(%base%, %date%, DAYS) Function would suppy a suitable integer for the %date%, where %base% is a fixed date such as DateAt(1,1,1), which is the =DayNumber() base date of 1 Jan 0001.
It does better than =DayNumber() and supplies an integer for all but Null Dates and Date Phrases.
Unfortunately, it miscalculates the DAYS for any date without a Day or Month component.
Excel Spreadsheet of Exported Dates, DayNumber & Timespan:

This has been Sorted on the Timespan column.
Note that the dates between 1845 and 1830 are not sorted correctly due to the =Timespan() miscalculation.
Help!!!!
ID:4785
These may be exported using Query Menu > Save Query Result Set As > Comma-Separated CSV File.
The CSV file can be opened with Excel but the Date column is displayed oddly.
See later spreadsheet image for examples.
Some Dates left-justify in column and display in Formula Bar as 7 November 1845.
Other Dates right-justify in column as 09-May-14 and in Formula Bar as 09/05/1914.
A Google search reveals that Excel and other Spreadsheets do not recognise dates before 1 Jan 1900 and treat them as text!!!
Any attempt to Format Cells as Date does not help.
Any attempt to Format Cells as Text results in the right-justified dates becoming large integers!
The only technique that helps, is to force each Query Result Date to be a text string in Excel by prefixing each date with an apostrophe ( ' ).
For example define the Query Column Date as =Text('' ' . %INDI.BIRT.DATE%).
However, in all the above cases it is impossible to Sort the Excel column of Dates into date order.
Therefore, you are forced to accept the sort order supplied by the FH Query.
Example Excel Spreadsheet of Exported Dates:

Maybe the =DayNumber(%date%) Function would supply an integer for the %date% that could act as a sort column.
Unfortunately, it only supplies an integer for a limited subset of FH date formats, where Day & Month & Year are all defined.
Maybe the =Timespan(%base%, %date%, DAYS) Function would suppy a suitable integer for the %date%, where %base% is a fixed date such as DateAt(1,1,1), which is the =DayNumber() base date of 1 Jan 0001.
It does better than =DayNumber() and supplies an integer for all but Null Dates and Date Phrases.
Unfortunately, it miscalculates the DAYS for any date without a Day or Month component.
Excel Spreadsheet of Exported Dates, DayNumber & Timespan:

This has been Sorted on the Timespan column.
Note that the dates between 1845 and 1830 are not sorted correctly due to the =Timespan() miscalculation.
Help!!!!
ID:4785