Jump to content

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


rachwilbraham

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']));

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.