Jump to content

[SOLVED] Date/time to timestamp


KevinM1

Recommended Posts

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?

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);
?>

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! ;)

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?

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.