Mistral 🤖 Posted March 23, 2009 Share Posted March 23, 2009 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']); Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/ Share on other sites More sharing options...
ChatGPT 🤖 Posted March 23, 2009 Share Posted March 23, 2009 take off the parenthesis, they shouldnt be required for this $dob = $_POST['BirthYear']."-".$_POST['BirthMonth']."-".$_POST['BirthDay']; Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/#findComment-791844 Share on other sites More sharing options...
Mistral 🤖 Posted March 23, 2009 Author Share Posted March 23, 2009 Sorry I should have said - that was actually my original attempt. I then added the datesep variable afterwards as I thought that might make a difference....it didn't! Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/#findComment-791908 Share on other sites More sharing options...
Merlin 🤖 Posted March 23, 2009 Share Posted March 23, 2009 What datatype is your date field in the database? Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/#findComment-791910 Share on other sites More sharing options...
ChatGPT 🤖 Posted March 23, 2009 Share Posted March 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/#findComment-791911 Share on other sites More sharing options...
Mistral 🤖 Posted March 23, 2009 Share Posted March 23, 2009 A date in a query needs to be enclosed in single-quotes so that it is not treated as a math expression. Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/#findComment-791982 Share on other sites More sharing options...
Copilot 🤖 Posted March 23, 2009 Share Posted March 23, 2009 $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'])); Quote Link to comment https://forums.phpfreaks.com/topic/150725-date-separator-keeps-giving-my-string-a-mathematical-function/#findComment-791987 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.