I am pulling date objects from the database that h...
# cfml-general
d
I am pulling date objects from the database that have the date object format: {ts '2025-02-13 000000'} And would like to format the cell that it is placed in as something other than YYYY-MM-DD but I can't work out the Excel DataFormats to do so. We have our clients date formats in a request variable of datef as either "mm/dd/yyyy" or "dd/mm/yyyy" How should I use dataformat to apply international date for excel of "dd/mm/yyyy" ? I am using simplicity Spreadsheet.
e
this may or may not be helpful depending on how you are using it. when generating html table for excel to auto open and convert, i finally found a bunch style attributes that can be set for excel to interpret the data type of the cell
Copy code
<td style="mso-number-format:'mm\/dd\/yyyy';">05/21/2023</td>
<td style="mso-number-format:'d-mmm-yy';">21-May-23</td>
👍 1
s
I may be missing something, but is there some reason you can't just use
dateFormat(myDateObj, 'mm/dd/yyyy')
formatting a value from the DB before putting it into the database is pretty standard
e
excel may take whatever date format it sees, recognize it as a date, but then apply its own default date format to the cell.
👆 2
p
Erin is correct, Excel sees date and automatically applies whatever if thinks for the formatting
c
@David Johnson You can control the date format Spreadsheet CFML uses by default when populating spreadsheet cells by passing it in when you instantiate the library. e.g.
Copy code
spreadsheet = new spreadsheet.SpreadSheet( dateFormats={ DATE: "mm/dd/yyyy" } )
You can also do it post-instantiation by calling the setDateFormats() method.
Copy code
spreadsheet.setDateFormats( { DATE: "mm/dd/yyyy" } )
3
d
Setting it in the instantiation has worked for me. We have international clients and some require dd/mm/yyyy. Thanks so much for the responses!
👍 1