spires Posted February 23, 2007 Share Posted February 23, 2007 Hi, Just a quick question. I'm storing the time of use input into my database useing the time() function. when i pull the info out of the database, how do i get it display the time? At the moment i get - 1172262700 I want it to say something like - 20:30 How do i go about doing this? Thanks for all of your help. Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 I think what you want is the date() function. It can show you all sorts of time related information. You have to write something like echo date("d"); or something like that. Different letters in the time function display different information. Go to http://us2.php.net/manual/en/function.date.php for a list of all the things the date function can display. Michael Quote Link to comment Share on other sites More sharing options...
spires Posted February 23, 2007 Author Share Posted February 23, 2007 I normally use the date function. However, this only display the date in the wrong order, I have been told that with the time function i can display it in the right order. Example: DATE() I want - 12.5.2007 I get - 2007.5.12 If you know a way of reversing this, that would really help me out. Thanks Quote Link to comment Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 You are storing unix timestamps. You can return it correctly formatted directly from MySQL. SELECT DATE_FORMAT(FROM_UNIXTIME(1172262700), '%k:%i') //20:30 or SELECT DATE_FORMAT(FROM_UNIXTIME(1172262700), '%l:%i %p') //8:30 PM Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Using the date() function allows you to format the date however, you want. Read the manual on it. Quote Link to comment Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 Check out the manual for php's date() function or mysql's date_format() function. Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 What they are trying to say is you can use more than one letter in the function. For example: echo date("l, F d, Y"); should give you something like Friday, February 23, 2007 Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 23, 2007 Share Posted February 23, 2007 <?php $fetch=mysql_fetch_assoc(mysql_query("SELECT mydate FROM mytable")); $mydate=$fetch['mydate']; echo 'Date from the database: '.$mydate.'<br />'; echo 'Newly formatted: '.date("d.m.Y",$mydate) ?> Hope that helps - I think I've got the date the write way round. As mentioned above, read up on date() for a complete list on how to format it how you want it. EDIT: Fixed a typo and swapped the date format around to how you wanted it. Quote Link to comment Share on other sites More sharing options...
spires Posted February 23, 2007 Author Share Posted February 23, 2007 Hi Guys, I'm slowly getting there. 'Yesideez' I've tryed out your way and i get this: Date from the database: 2007-02-23 Newly formatted: 01.01.1970 I have had 01.01.1970 come up lots of times before when trying things out. Any more suggestions? Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 You need to use strtotime() as well echo 'Newly formatted: '.date("d.m.Y",strtotime($mydate)) Quote Link to comment Share on other sites More sharing options...
spires Posted February 23, 2007 Author Share Posted February 23, 2007 Your a star Jesirose. It works perfect And thanks to everyone else who helped. This simple little problem has been driving me mad for a while now. Quote Link to comment Share on other sites More sharing options...
chrisredding Posted February 23, 2007 Share Posted February 23, 2007 Just for reference to make a UK formatted date (and 24 hour time): date("d/m/Y H:i") Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 23, 2007 Share Posted February 23, 2007 You need to use strtotime() as well echo 'Newly formatted: '.date("d.m.Y",strtotime($mydate)) Oops lol I always make that mistake. You'd think I'd have learnt by now the number of times I've used it Quote Link to comment 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.