Jump to content

Date Output Help


Go to solution Solved by Muddy_Funster,

Recommended Posts

Hi Guys,

 

Just looking for some quick advice on code - newbie here

 

My code is as follows

<td>{$result['cdate']}</td>

<td>{$result['mdate']}</td>

This successfully outputs my date in the format 2013-05-08 12:24:04 - however I would like it as 08 July 2013 12:24:04

 

The cdate is a datetime and mdate is a timestamp in mysql database.

 

I have been reading about srttotime and can't get my head around it, any help is appreciated.

 

Thanks in advance,

 

J

Link to comment
https://forums.phpfreaks.com/topic/280642-date-output-help/
Share on other sites

apologies, I will try to clarify

 

In one of my other php pages I have the code below

<td> '.date("d-M-Y H:i:s", strtotime($result['cdate'])).' </td>

This successfully outputs this text 30-Jul-2013 11:55:00

 

Is it possible to implement such code into the code below (without having to change querys etc)

 

<td>{$result['cdate']}</td>


<td>{$result['mdate']}</td>

This is a project I am taking over from another person, and just needs fine tuned to be completed.

 

Thanks again for the help.

 

If I'm making no sense let me know!

 

J

Link to comment
https://forums.phpfreaks.com/topic/280642-date-output-help/#findComment-1442686
Share on other sites

You have two options. You can either have the date formatted within your query - so you don't have to do anything with the value once returned. Or, you can format it within PHP. There are benefits and drawbacks to both and the determination would be based on many factors (e.g. do the date/times need to be timezone aware for the user).

 

But, in either case, you can format the date in any manner you wish. strtotime() is only needed to convert the date string to a timestamp - it is the date() function that determines what the format it: http://php.net/manual/en/function.date.php

 

For the format "08 July 2013 12:24:04", you would use "d F Y H:i:s" - this assumes you want the hour n 24 hour format.

 

date("d F Y H:i:s", strtotime($result['cdate']))
Link to comment
https://forums.phpfreaks.com/topic/280642-date-output-help/#findComment-1442688
Share on other sites

  • Solution

just apply the same successfull line of code to the other $result[] outputs to the rest of the outputs that you want to match that format.

Sorry, I missread the first post and thought that you had the date in one column and the time in another.

Link to comment
https://forums.phpfreaks.com/topic/280642-date-output-help/#findComment-1442689
Share on other sites

thanks for the tips guys!

 

OK now I have the code below;

<td>Date of Request</td>
<td>{$result[date("d-F-Y H:i:s", strtotime($result['cdate']))]}</td>
    
<td>Date Last Modified</td>
<td>{$result['mdate']}</td>

The first row cdate (date of request) doesn't output any date at all now

 

The second row mdate (date last modified) outputs 2013-07-30 11:55:00

 

Maybe I need to go away and start at the beginning with PHP!

Edited by johnnys2
Link to comment
https://forums.phpfreaks.com/topic/280642-date-output-help/#findComment-1442693
Share on other sites

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.