Solved

Format Date

Posted on 2004-09-01
14
299 Views
Last Modified: 2006-11-17
I have searched several past posts on this subject but none really answer my question.

I printed out a date field to the php report I created.  The date shows with time like this:

2004-08-25 13:25:16

I want to get rid of the time and also format it like this

08-25-2004 where the date is mm/dd/yy

Here is my code in my php page that spits out the time:

$regdate = $row->CreateDate;
print("<td width=\"10\" class=\"bodyblack_l\">&nbsp;</td><td class=.$strRowClass.><b>$count)</b>&nbsp;<b>$row->FName $row->LName</b></td><td align=\"center\" class=\"checkbox\">&nbsp;$p</td><td class=\"strRowClass\">$regdate</td><td width=\"10\" class=\"bodyblack_r\">&nbsp;</td>\n");
0
Comment
Question by:dba123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
14 Comments
 
LVL 4

Expert Comment

by:iceboxman
ID: 11954698
Try this:

$regdate = date("m-d-y", strtotime($regdate));
0
 
LVL 4

Expert Comment

by:iceboxman
ID: 11954720
My above code will convert your time string into a timestamp, the reformat the timestamp to a string.
0
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 500 total points
ID: 11954809
Actually, if you want the four-year date, the following will accomplish that:

$regdate = date("m-d-Y", strtotime($regdate));

Many more options can be seen at: http://us4.php.net/manual/en/function.date.php
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 1

Author Comment

by:dba123
ID: 11954834
not workinwhat about the CreateDate field...it is totally left out.  When I use yours, I get weird dates
0
 
LVL 1

Author Comment

by:dba123
ID: 11954866
I tried this:

$regdate = date("m-d-Y",$row->CreateDate);

but it made every date render as 12-31-1969  to the page

0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11954878
not sure how well strtotime handles that kind of string, i would have though it would work fine but as your only focusing on the date try the following

$regdate = $row->CreateDate;
$parts = explode(" ",$regdate);
$regdate = date("m-d-Y", strtotime($parts[0]));
0
 
LVL 1

Author Comment

by:dba123
ID: 11954908
whoops, there we go

$regdate = date("m-d-Y", strtotime($row->CreateDate));
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11954931
iceboxman's answer should have been accepted really, or atleast a split.
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 11954941
I agree - can I do that somehow?
0
 
LVL 4

Expert Comment

by:iceboxman
ID: 11955126
But dba123 needs to do it.
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 11955127
Yeah, that's for the person who asked the question though - is there any way the receiver of the points can split?
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11955168
3 options from the "expert perspecitve"

1) cLFlaVA creates a question entitled "points for iceboxman" however this will take the total points for this question over 500 thus violating the rules

2) wait for dba123 his opinion

3) Be graceful and appreciate that the question asker got his answer which is the most important thing and be happy that you've helped.
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 11955288
Whatever works.  I'm new here - I just don't want to step on anyone's toes.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question