Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date help

Status
Not open for further replies.

JamesManke

Programmer
Jul 1, 2004
54
CA
I have a variable in my database called date.

Example: Say the variable date in the databases value is 2005-05-05

How do I make this variable say...

May 5th, 2005
 
Like this....

Code:
[blue]

echo date("M-d-Y", mktime(0,0,0,5,5,2005));

[/blue]

Cheers!

cout << "If you don't know where you want to go, we'll make sure you get taken";
 
I am using DATE("M-d-Y",$type[showdate])

$type[showdate] in the database is 2001-05-05

For some reason when using DATE("M-d-Y",$type[showdate]) it reads Dec-31-1969

Is this weird or what!
......heeelp!
 
I'm sure this is not the best way to accomplish this but here you go.


// explode my date into an array to separate it into variables.
$mydate = explode('-',$rec['showdate']);
// separate out the components assuming format is YYYY-MM-DD
$y = $mydate[0]; // year is first
$m = $mydate[1]; // month is second
$d = $mydate[2]; // day is last

$month_name = date("F",mktime(0,0,0,$m,1,$y)); // convert to month name
$day = date("j",mktime(0,0,0,$m,$d,$y)); // remove leading zeros from the day if any
$cardinal = date("S",mktime(0,0,0,$m,$d,$y)); //get the cardinals for the day
echo "$month_name $day$cardinal, $y"; // print the date

Again, I don't know the most efficient way but this works for me.

Hope it helps.
Meekos
 
Thanks Guys! Works great - nice to a variety of options!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top