user4942382
user4942382

Reputation:

SQL Varchar to milliseconds

I have a column in my MySql database which stores a date as a string "dd/mm/yyyy" is there a way for me to have this in an update query where I can check if the date in the table is overdue compared to now().

I've had a look at the CONVERT function but can't figure out how to use it for my case.

Upvotes: 0

Views: 148

Answers (2)

Dylan Su
Dylan Su

Reputation: 6065

Try this:

SELECT ... FROM ... WHERE STR_TO_DATE(col, '%d/%m/%Y') > NOW()

Upvotes: 0

Abhishek Sharma
Abhishek Sharma

Reputation: 6661

STR_TO_DATE() converts the str string into a date value based on the fmt format string. The STR_TO_DATE() function may return a DATE , TIME, or DATETIME value based on the input and format strings. If the input string is illegal, the STR_TO_DATE() function returns NULL.

SELECT STR_TO_DATE('21/5/2013','%d/%m/%Y');

With time :-

SELECT STR_TO_DATE('01/01/2013 1130','%d/%m/%Y %h%i') ;

compare with now()

Where now()=STR_TO_DATE('01/01/2013 1130','%d/%m/%Y %h%i') ;

Upvotes: 1

Related Questions