Jump to content

Need to store user entered dates


arcdragon

Recommended Posts

I am trying to take a user entered month, day, and year from an HTML/PHP form and store it in a mySQL database..

 

Code:

$exp_date = date('n/d/Y', strtotime($_POST['exp_month'] . '/' . $_POST['exp_day'] . '/' . $_POST['exp_year']));

 

Expected result for $exp_date:

MM/DD/YYYY

 

But instead I'm getting:

0.000004, which seems to be the result of dividing the variables together.  And completely incapable of being stored in a DATE formatted field.

 

Please help.  I'm starting to claw at my eyes.  Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/184067-need-to-store-user-entered-dates/
Share on other sites

A mysql DATE data type has a format YYYY-MM-DD, not MM/DD/YYYY.

 

DATE values are strings and must be encompassed in single-quotes in the query. When they are not enclosed in single-quotes, they are a math expression (the correct YYYY-MM-DD format is a subtraction math expression and the format you are attempting is a division math expression.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.