1

I have this code. my problem is the strduedate field is in varchar type. How can I convert that field into datetime so I can perform the greater than query.

scenario.

Given the strduedate in my database is = '01/02/2016'

when I perform the query it says that strduedate is less than current date which is 09/18/2015.

$date_now = new DateTime();

$sql = "UPDATE jrf_tbl SET strifoverdue ='no' WHERE strduedate > '$date_now' ";
$OverDue->updatefields($sql);
1
  • STR_TO_DATE(str,format) - STR_TO_DATE(strduedate, '%m/%d/%Y') Commented Sep 18, 2015 at 3:04

1 Answer 1

2

Just use the mysql STR_TO_DATE function like this:

$sql = "UPDATE jrf_tbl SET strifoverdue ='no' WHERE STR_TO_DATE(strduedate, '%m/%d/%Y') > '$date_now' ";
$OverDue->updatefields($sql);
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.