Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.