0

I am using bootstrap datetimepicker and using format as YYYY-MM-DDTHH:mm:ssZ the text input I am storing as it is in database column.

I have to store it as string only. While fetching records I am passing fromdate and toDate which are for applications timezone (other than client machine). We set timezone through application as well.

For MySQL query I am doing date comparison using:

str_to_date(column_name,'%Y-%m-%dT%T')

This gives an issue in fetching records. Any suggestions?

My problem is when I am not sure whether I am right about datetimepicker format.

1 Answer 1

2

I have to store it as string only.

Stop. Right there. There are very few reasons why you would really want to store your dates and timestamps in a MySQL database as pure text. Instead, you should be using a date column, which would alleviate your need to call STR_TO_DATE in the first place.

With regard to your call to STR_TO_DATE, I think your format mask should be this:

STR_TO_DATE(column_name, '%Y-%m-%dT%H:%i:%sZ')

This appears to be working in the demo below.

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.