Steffen Posted April 2, 2006 Share Posted April 2, 2006 Hi allI've been searching for one hour now on the internet for an easy solution for strotime in combination with dates prior to 1970 (on Windows platform).So, on my localhost strotime("1950-06-02") returns -1 instead of a timestamp.I know there is a solution...I just can't find it:(Grtz and thx Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/ Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360833:date=Apr 2 2006, 10:01 AM:name=Steffen)--][div class=\'quotetop\']QUOTE(Steffen @ Apr 2 2006, 10:01 AM) [snapback]360833[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi allI've been searching for one hour now on the internet for an easy solution for strotime in combination with dates prior to 1970 (on Windows platform).So, on my localhost strotime("1950-06-02") returns -1 instead of a timestamp.I know there is a solution...I just can't find it:(Grtz and thx[/quote]the best workaround's i have found for dealing with this is in the manual: [a href=\"http://uk.php.net/strtotime\" target=\"_blank\"]http://uk.php.net/strtotime[/a] . its mostly the users comments you want to read as several of them discuss ways around pre-1970 dates.hope it helps!Cheers Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23105 Share on other sites More sharing options...
Steffen Posted April 2, 2006 Author Share Posted April 2, 2006 i searched there already...i didnt find it:(thx! Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23106 Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360839:date=Apr 2 2006, 10:44 AM:name=Steffen)--][div class=\'quotetop\']QUOTE(Steffen @ Apr 2 2006, 10:44 AM) [snapback]360839[/snapback][/div][div class=\'quotemain\'][!--quotec--]i searched there already...i didnt find it:(thx![/quote]there's a function that a user has written, on that page i gave you, that is a replacement for strtotime that deals with pre-1970 dates:[code]function safestrtotime ($s) { $basetime = 0; if (preg_match ("/(\d\d\d\d)/", $s, $m) && ($m[1] < 1970)) { if( $m[1] < 1902 ) { return -1; } $s = preg_replace ("/19\d\d/", $m[1]+68, $s); $basetime = 0x80000000 + 1570448; } $t = strtotime( $s ); return $t == -1 ? -1 : $basetime + $t;}[/code]do a search on the page for '1970' and you'll find several solutions. the above is just one of them Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23107 Share on other sites More sharing options...
Steffen Posted April 2, 2006 Author Share Posted April 2, 2006 Yes, i tried one of those functions before but i had a problem with date(). so, now i have the same problem. One I try to convert the timestamp to a date it results in 19 january 2038 (= maximum value -> cfr php.net)How can i solve the date function then?Thx a lot! Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23117 Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360851:date=Apr 2 2006, 01:47 PM:name=Steffen)--][div class=\'quotetop\']QUOTE(Steffen @ Apr 2 2006, 01:47 PM) [snapback]360851[/snapback][/div][div class=\'quotemain\'][!--quotec--]Yes, i tried one of those functions before but i had a problem with date(). so, now i have the same problem. One I try to convert the timestamp to a date it results in 19 january 2038 (= maximum value -> cfr php.net)How can i solve the date function then?Thx a lot![/quote]well its safe to say that the function you've seen is pretty much the only way to convert one way. but because it's a custom function, my guess is that you'll have to write a custom function to convert it back, taking into account that negative values from the function off php.net is the amount of seconds BEFORE 1/1/1970. may take a little trial and error but shouldn't be too tricky, but date() only accepts a normal (positive) timestamp, not a custom-generated negative one. Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23133 Share on other sites More sharing options...
Barand Posted April 2, 2006 Share Posted April 2, 2006 What are you trying to do? There may be another solution that doesn't require strtotime(). Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23208 Share on other sites More sharing options...
Steffen Posted April 2, 2006 Author Share Posted April 2, 2006 I have a input form with year, month and day input fields. I convert it to a timestamp (with the new safestrotime function) to store it in the database (as VARCHAR). Then I select it and parse it with the date function...so it should return the date again...thx a lot Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23217 Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360955:date=Apr 2 2006, 08:31 PM:name=Steffen)--][div class=\'quotetop\']QUOTE(Steffen @ Apr 2 2006, 08:31 PM) [snapback]360955[/snapback][/div][div class=\'quotemain\'][!--quotec--]I have a input form with year, month and day input fields. I convert it to a timestamp (with the new safestrotime function) to store it in the database (as VARCHAR). Then I select it and parse it with the date function...so it should return the date again...thx a lot[/quote]do you HAVE to store it in the database as a timestamp (and why varchar anyway?) - why not just store it as a DATE type? Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23219 Share on other sites More sharing options...
Barand Posted April 2, 2006 Share Posted April 2, 2006 A MySql DATE type column can hold dates between '1000-01-01' and '9999-12-31'.You can't use unix date functions on anything before 1970 but MySql DATE_FORMAT() etc should work. Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23221 Share on other sites More sharing options...
Steffen Posted April 3, 2006 Author Share Posted April 3, 2006 ok, i will try that...but i never worked with it....but i'll find out^^! Quote Link to comment https://forums.phpfreaks.com/topic/6389-strotime-with-dates-prior-to-1970/#findComment-23400 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.