close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Unix Timestamp to dd-mm-yyyy

Thread began 7/09/2011 11:32 pm by neilo | Last modified 7/11/2011 3:57 pm by Jason Byrnes | 2957 views | 8 replies |

neilo

Unix Timestamp to dd-mm-yyyy

Hi,

I have a recordset from which I query:

$query_rs_data = "SELECT time_last_run FROM phpmysqlautobackup";

which I use to output a Date:

<?php echo $row_rs_data['time_last_run']; ?>

The 'time_last_run' value is a Unix timestamp, i.e: 1310250618 (seconds from start of Unix epoch).

How can I output this to page as dd/mm/yyyy instead of 1310250618 (without it outputting 1st Jan 1970).

Help appreciated.

Sign in to reply to this post

neilo

Thanks Dave

Thanks to Dave Buchholz (yet again) whose post I found Here

So for my example above, it was:

$query_rs_data = "SELECT DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL time_last_run SECOND), '%b %d %Y %h:%i %p') As LASTRUN FROM phpmysqlautobackup";

and

<?php echo $row_rs_pg['LASTRUN']; ?>

which output: Jul 09 2011 11:34 PM

Perfect. Cheers Dave.

Sign in to reply to this post

Jason ByrnesWebAssist

just to keep your options open, another way to accomplish this is using the php date function:

example:

php:
<?php echo(date("d/m/Y"$row_rs_data['time_last_run'])); ?>
Sign in to reply to this post

neilo

Hi Jason,

Thanks, - I tried this (as is, and in variations thereof) but this kept returning 01/01/1970.

Sign in to reply to this post

Jason ByrnesWebAssist

perhaps try:

php:
<?php echo(date("d/m/Y"strtotime($row_rs_data['time_last_run']))); ?>
Sign in to reply to this post

neilo

Yes, I'd have thought that would do it, but it still returned 01/01/1970

Just echoing the value; <?php echo $row_rs_test['time_last_run']; ?>

returns the unix date (in seconds from Unix beginning date): 1310250898

Using the regular php date functions doesn't seem to increment this value on to the Unix (epoch start) date and print it as a recognizable date format.

Sign in to reply to this post

Jason ByrnesWebAssist

not at all sure what the problem may be.

This code, for me:
<?php echo(date("d/m/Y", "1310250618")); ?>


returns:
09/07/2011

Sign in to reply to this post

neilo

The problem is the same one that keeps cropping up, i.e. - me.

Running it again on a fresh test page (with recordset rs_test) with your first code:

<?php echo(date("d/m/Y", $row_rs_test['time_last_run'])); ?>

Returns the date just fine. I now need to back-track and see how I messed up the first time.

I think it is my destiny to make others feel better about themselves and their abilities by displaying my ignorance on these pages. Thanks for helping out - sorry to have wasted your time again,

n.

Sign in to reply to this post

Jason ByrnesWebAssist

No worries, glad to hear you got it working.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...