• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Format Date

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
dba123
Asked:
dba123
  • 4
  • 4
  • 3
  • +1
1 Solution
 
iceboxmanCommented:
Try this:

$regdate = date("m-d-y", strtotime($regdate));
0
 
iceboxmanCommented:
My above code will convert your time string into a timestamp, the reformat the timestamp to a string.
0
 
cLFlaVACommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
dba123Author Commented:
not workinwhat about the CreateDate field...it is totally left out.  When I use yours, I get weird dates
0
 
dba123Author Commented:
I tried this:

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

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

0
 
Diablo84Commented:
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
 
dba123Author Commented:
whoops, there we go

$regdate = date("m-d-Y", strtotime($row->CreateDate));
0
 
Diablo84Commented:
iceboxman's answer should have been accepted really, or atleast a split.
0
 
cLFlaVACommented:
I agree - can I do that somehow?
0
 
iceboxmanCommented:
But dba123 needs to do it.
0
 
cLFlaVACommented:
Yeah, that's for the person who asked the question though - is there any way the receiver of the points can split?
0
 
Diablo84Commented:
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
 
cLFlaVACommented:
Whatever works.  I'm new here - I just don't want to step on anyone's toes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now