KevinM1 Posted June 6, 2007 Share Posted June 6, 2007 Is there any built-in PHP function that can turn something like "2007-04-18 18:00:00" into a timestamp? Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/ Share on other sites More sharing options...
taith Posted June 6, 2007 Share Posted June 6, 2007 strtotime(); Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-269312 Share on other sites More sharing options...
chigley Posted June 6, 2007 Share Posted June 6, 2007 You can try strtotime().. Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-269313 Share on other sites More sharing options...
KevinM1 Posted June 12, 2007 Author Share Posted June 12, 2007 Okay, thanks! Related question: is there a built-in function that does the opposite? That is, can I feed a function a timestamp and have it return a date and time? I don't see one after skimming over the PHP online manual, but I figured I'd ask anyway. If not, what would be the algorithm in transforming a timestamp into a normal date and time? Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273264 Share on other sites More sharing options...
obsidian Posted June 12, 2007 Share Posted June 12, 2007 Okay, thanks! Related question: is there a built-in function that does the opposite? That is, can I feed a function a timestamp and have it return a date and time? I don't see one after skimming over the PHP online manual, but I figured I'd ask anyway. If not, what would be the algorithm in transforming a timestamp into a normal date and time? date() <?php $timestamp = time(); echo date('Y-m-d h:i:s', $timestamp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273265 Share on other sites More sharing options...
KevinM1 Posted June 12, 2007 Author Share Posted June 12, 2007 Okay, thanks! Related question: is there a built-in function that does the opposite? That is, can I feed a function a timestamp and have it return a date and time? I don't see one after skimming over the PHP online manual, but I figured I'd ask anyway. If not, what would be the algorithm in transforming a timestamp into a normal date and time? date() <?php $timestamp = time(); echo date('Y-m-d h:i:s', $timestamp); ?> Thanks mang! Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273272 Share on other sites More sharing options...
KevinM1 Posted June 12, 2007 Author Share Posted June 12, 2007 I thought I had the problem solved, but I guess not. Here's what's going on: I have dates stored in a MySQL database as a datetime data type. I need to extract them from the database and turn them into timestamps to be sent to a form via GET. Then, once that form has them, I need to convert them back into a human-sensible form, as my form will e-mail the site owner whenever someone submits the form. From what I can tell with my debugging, my problem lies in not being able to extract those datetimes from the database. I tried outputting them to screen as-is (that is, before I try converting them to a timestamp), and nothing shows up. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273291 Share on other sites More sharing options...
pocobueno1388 Posted June 12, 2007 Share Posted June 12, 2007 Could you post your code? Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273294 Share on other sites More sharing options...
Wildbug Posted June 12, 2007 Share Posted June 12, 2007 So you've done "SELECT your_datetime_col FROM your_table" and it came back empty? If so, you need to fill it. For converting datetimes in MySQL to Unix-style timestamps, use "SELECT UNIX_TIMESTAMP(your_datetime_col) FROM your_table". You can either convert it to another format within PHP using the date() function, or select both formats from the table initially. Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273301 Share on other sites More sharing options...
KevinM1 Posted June 12, 2007 Author Share Posted June 12, 2007 Since I'm trying to modify PHP Fusion AND an event calendar addon, it's somewhat difficult to put my code online. It's spread throughout many files due to the spaghetti-code nature of PHP Fusion. Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273303 Share on other sites More sharing options...
KevinM1 Posted June 12, 2007 Author Share Posted June 12, 2007 So you've done "SELECT your_datetime_col FROM your_table" and it came back empty? If so, you need to fill it. For converting datetimes in MySQL to Unix-style timestamps, use "SELECT UNIX_TIMESTAMP(your_datetime_col) FROM your_table". You can either convert it to another format within PHP using the date() function, or select both formats from the table initially. In know for a fact that the values for the datetime columns in question are indeed filled. They're looking at me in phpMyAdmin. To be honest, I'm not sure if the db query is even retrieving those columns. Trying to find where the actual query is made has been a real pain because, like I said above, I'm trying to tweak a PHP Fusion addon. The code isn't very obvious in that regard. I think they are being retrieved, however, as wouldn't MySQL give an error if I was trying to use a column not returned by a query? Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273311 Share on other sites More sharing options...
Wildbug Posted June 12, 2007 Share Posted June 12, 2007 You have to check for an error. Are you? $result = mysql_query($query); if (mysql_errno()) die(sprintf('Error: %s<br/>Query: %s<br/>',mysql_error(),$query)); Can you grep the source to find where the query is being made? Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-273319 Share on other sites More sharing options...
KevinM1 Posted June 14, 2007 Author Share Posted June 14, 2007 I finally got it to work. The problem stemmed from PHP Fusion's built-in database code. Works like a charm now. Quote Link to comment https://forums.phpfreaks.com/topic/54453-solved-datetime-to-timestamp/#findComment-274571 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.