Jump to content

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.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.