Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Date separator...? Keeps giving my string a mathematical function!


Recommended Posts

Hi,

 

I'm taking form variables and joining the string together to enter it as a date in a mysql table.  My dates should look like 2009-03-23 in the mysql table.  I've written the following code but it keeps giving me the year minus the month minus the day....sorry for being really dumb about this but how do i make sure the separator is recognised as text???

 

Thanks!!

 

$datesep = "-";
$dob = ($_POST['BirthYear'].$datesep.$_POST['BirthMonth'].$datesep.$_POST['BirthDay']);	

the only other thing that I can think of is that the dates are stored as Int values in your database, so it is assigning an Int value by default to $dob and performing the mathematical operation on it.

 

I am not sure if this will work or not, but what happens if you initialize $dob as a string;

 

$dob="";

$dob= .... what you had before;

 

and if that doesn't work, look up on google how to cast a variable as a string, I am not sure how to do it exactly

$dob = $_POST['BirthYear']."-".$_POST['BirthMonth']."-".$_POST['BirthDay'];
mysql_query("UPDATE table SET dob='".$dob."'");

 

Not sure if leading zeros are needed...

 

$dob=date('d-m-Y',strtotime($_POST['BirthYear']."-".$_POST['BirthMonth']."-".$_POST['BirthDay']));

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.