Convert from mysql datetime to coldtusion datetime

Does anyone know a simple way to convert mysql datetime values ​​to coldfusion date and time values ​​in CF8 (and maybe it should be backward compatible with CF6)?

I need to store dates in mysql and select them for storage in mysql datetime format so that I can get db for date ranges and comparisons for me. I could do this in CF, but I would have to get a potentially huge set of results for processing. It seems very reasonable to get db to handle this for me.

My front end code is coldfusion, and converting cf time objects to what mysql understands when pasting is simple enough. But I ran into problems, returning them the other way.

There is a CreateDateTime function, but first I need to first split the mysql result into separate parts of the year, month, day, etc. It's not complicated, but it seems unnecessarily complicated compared to converting dates in the other direction.

The ParseDateTime function is not suitable for me because I want to continue processing server-side datetime objects before formatting and sending to the client.

Does anyone know an easy way to do this? Or should I agree to an easy conversion to one side and the other to the other?

+3
source share
2 answers

date_format very suitable for this:

date_format(myDateCol, '%m/%d/%Y')

In addition, if you need to make calculations about this, it date_formatmay just be your wrapper:

date_format(date_add(myDateCol, interval 7 day), '%m/%d/%Y')

(7 ) ColdFusion.

+3

CreateODBCDateTime ().

+2

Source: https://habr.com/ru/post/1715684/


All Articles