Skip to content
Advertisement

How to compare dates which is stored as String(varchar) in database?

I have a database(table), in which 2 fields are:

Dates are stored in this fashion:

For ex: ‘2014-10-30 10:10:10’ in database.

Now I want to compare two dates and fetch records from database by using query, 2014-09-10 10:10:10(fromdate) to 2014-10-10 10:10:10(todate)

How to fetch all accurate records.. Is there any kind of solution..

Thanks.

Advertisement

Answer

Just compare the string without extra overhead.

This format “YYYY-MM-DD HH:mm:ss” shares chronological and literal alphabetical order

Also, I would create an index on those columns.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement