adam84 Posted May 4, 2011 Share Posted May 4, 2011 Howdy, I have a question about Dates in PHP 5.3.6. I queried my database (SQL Server 2008) and I got back two columns, a date(StartDate) and a time(StartTime). The software we used only allows the user to enter a StartDate, so that field always has a value, but there are instances where the StartTime is null (no time set). What I want to do is if there is a StartTime, concat it to the StartDate. If there is not StartTime, I want to add a default time. But when I do that, I get an error saying that I cannot combine a string and a date. I really do not understand why this is happening. I set up PHP 5.3.6 on a server, so I am not sure if there something in the php.ini file that is not allowing me or if this is something new. Some help please! Thanks if( $row['StartTime'] != null ) $sTime = $row['StartDate'] . " " . $row['StartTime']; //What I want '2011-05-03 17:58:12.000' else $sTime = $row['STartDate'] . " 00:00:00.000"; //What I want '2011-05-03 00:00:000' Quote Link to comment https://forums.phpfreaks.com/topic/235549-php-536-question/ Share on other sites More sharing options...
requinix Posted May 4, 2011 Share Posted May 4, 2011 What do you use to access the database and what does the error message say? Quote Link to comment https://forums.phpfreaks.com/topic/235549-php-536-question/#findComment-1210602 Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 what are you receiving instead of the values that you want? Quote Link to comment https://forums.phpfreaks.com/topic/235549-php-536-question/#findComment-1210610 Share on other sites More sharing options...
adam84 Posted May 4, 2011 Author Share Posted May 4, 2011 I am using SQLSRV to access my Database. I receive the correct value, I just cannot do anything with it because it is a date. I cannot even explode the returned value because it says its type date not type string Quote Link to comment https://forums.phpfreaks.com/topic/235549-php-536-question/#findComment-1210613 Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 can i see the exact error that you are receiving so i can help further please? Quote Link to comment https://forums.phpfreaks.com/topic/235549-php-536-question/#findComment-1210620 Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 this should point you in the right direction, it would need altering to test it with your database values <?Php $date = strtotime("2011-05-03"); echo date("y-m-d H:i:s",$date); ?> <?php date("y-m-d H:i:s",$row['STartDate']); //is the T in StartDate a typo? ?> Quote Link to comment https://forums.phpfreaks.com/topic/235549-php-536-question/#findComment-1210664 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.