Techheadz Tips and Tutorials
Techheadz@Twitter
Enter Search Term
ID: 221 Category: PHP Date Posted: 17/04/2012 Page Impressions : 1,321
0
Print How to convert MySQL timestamp in PHP

How to convert MySQL timestamp in PHP

When you are dealing with times in PHP you would generally use a unix timestamp. A unix timestamp is always in seconds, and is always calculated from midnight (UTC) of Thursday, January 1, 1970. The Unix Timestamp could then be entered in to a database for example.

A unix timestamp can always be created in PHP using the following code below. The code below will generate the current time in seconds
<?php
$timestamp = time();
echo "Time is seconds: ". $timestamp;
?>
If you then wanted to convert this timstamp to a readable date in PHP you would use the following code
<?php
echo "Today's time and date: ". date('d-m-Y H:i:s', $timestamp);
?>
In the code above the d-m-Y displays date/month/year which is the UK format.

If you wanted to display the date in US format you would use m-d-Y

In the code above the H:i:s display the time Hours, Minutes, Seconds

It's really not that difficult dealing with times using PHP once you get your head around it.
For a start when you are dealing with time in seconds, it is a lot easier to manipulate and compare to times.


To view a live example, please click here

Related PHP Links

Live Demo - How to convert MySQL timestamp in PHP



 
Search Techheadz
Ubuntu Ubuntu - Install Adobe Reader in Ubuntu 12.04. sudo apt-get install acroread
Ubuntu Ubuntu - Install veetle in Ubuntu
Ubuntu Ubuntu - Install Putty in Ubuntu
Ubuntu Ubuntu - Install gparted in Ubuntu. sudo apt-get install gparted
Ubuntu Ubuntu - Install Sopcast in Ubuntu Unity 12.04
Ubuntu Ubuntu - Ubuntu 12.04. Make Unity Launcher Icons Smaller.
MySQL MySQL - Import - Export MySQL using the terminal in Ubuntu Linux
Ubuntu Ubuntu - Ubuntu swappiness. Improve ubuntu performance. vm.swappiness=10. sysctl.conf
Ubuntu Ubuntu - Convert .ogv file to .mp4, .webm, .avi in Ubuntu using ffmpeg
Kubuntu Kubuntu - Install Adobe Reader in Kubuntu 12.10, Ubuntu 12.10
Ubuntu Ubuntu - Install filezilla in Ubuntu
Ubuntu Ubuntu - Install Google Chrome in Ubuntu 12.04
Ubuntu Ubuntu - Sendmail not found in Ubuntu. Send mail is slow.
Apache Apache - How to Start, Stop, Restart an Apache Web Server (Linux Ubuntu)
Ubuntu Ubuntu - Install Sopcast Player in Ubuntu 12.10
MySQL MySQL - MySQL commands list. MySQL using the terminal.
Ubuntu Ubuntu - VirtualBox Failed to access the USB subsystem. sudo usermod -aG vboxusers {username}
Ubuntu Ubuntu - Could not update ICEauthority file
CSS CSS - Stretch table width and height to 100% of screen using css and html
Ubuntu Ubuntu - How do I install a firewall in Ubuntu 12.10, ufw UncomplicatedFirewall
CSS CSS - How to set table to 100% screen height using CSS and HTML
Ubuntu Ubuntu - Nautilus Image Converter. Batch resize images in Ubuntu.
Perl Perl - Install perl in Ubuntu
Ubuntu Ubuntu - Create a simple bash script in Ubuntu
PHP PHP - session.save_path. Change the PHP session path
Search Techheadz
Install Adobe Flash in ubuntu 12.04
Install Adobe Flash in ubuntu 12.04
codecs for ubuntu 13.04
stop mail server in plesk
dreamweaver
linux radio streams
ffmpeg
The following packages have unmet dependencies. sopcast-player : Depends: sp-auth (>= 3.0.1) but it is not installable E: Unable to correct problems, you have held broken packages
dreamweaver
export mysql
settings kde
putty ubuntu
editor C++ in ubuntu
editor c++
php editor Ubuntu. Dreamweaver
ubuntu install total
ubuntu total
domain name
sopcast
ubuntu bash scripts

Binary Clock
http://www.binaryti.me/
Home | About | Links | Add Your Link | Most Popular | Last Accessed | Related Links | Twitter | Site Map
Apache | CSS | HTML | Javascript | Linux |MySQL | Perl | PHP | Linux News & Games | Retro Computing | Ubuntu | Mint | Kubuntu | Win