Fearpig Posted April 5, 2007 Share Posted April 5, 2007 Hi Guys, I'm probably being thick here but I have a weird problem. I'm using the following line to format dates from an SQL database: $Format_Start_Date = date("d/m/Y",strtotime("$Start_Date")); This correctly formats my dates into dd/mm/YYYY but when it gets to a blank record it puts in 01/01/1970...? Any ideas as this is baffling me! Cheers, Tom Quote Link to comment https://forums.phpfreaks.com/topic/45730-solved-date-formatting/ Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 What you want to do if the record is blank ? Quote Link to comment https://forums.phpfreaks.com/topic/45730-solved-date-formatting/#findComment-222134 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 This note is on the strtotime manual page: Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though. If the above applies to you, that's what's happening. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45730-solved-date-formatting/#findComment-222137 Share on other sites More sharing options...
Fearpig Posted April 5, 2007 Author Share Posted April 5, 2007 Hi Jitesh... I'd just like it to be blank! Quote Link to comment https://forums.phpfreaks.com/topic/45730-solved-date-formatting/#findComment-222165 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Put an "if" statement before your conversion or use the ternary operator (scroll down): <?php if ($Start_Date != '') $Format_Start_Date = date("d/m/Y",strtotime($Start_Date)); else $Format_Start_Date = ''; ?> or <?php $Format_Start_Date = ($Start_Date != '')?date("d/m/Y",strtotime($Start_Date)):''; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/45730-solved-date-formatting/#findComment-222172 Share on other sites More sharing options...
Fearpig Posted April 5, 2007 Author Share Posted April 5, 2007 Thank you guys, I was trying to fix it but I should have just put in the "if/then"! Cheers. Tom Quote Link to comment https://forums.phpfreaks.com/topic/45730-solved-date-formatting/#findComment-222178 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.