Solved

Formatting Dates example 01 - January

Posted on 2004-04-02
3
285 Views
Last Modified: 2006-11-17
I am trying to convert a two digit Month (01,02 etc...) to (January, February etc..)

This is what I have, but it doesn't work:

$month = "02";
$date = strtotime($month);
$New_Month = date("F",$date);

Can anyone help? Thanks
0
Comment
Question by:Zambian4eva
3 Comments
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 10742559
change your middle line to something like

$date = strtotime($month . "/01/01");
0
 
LVL 5

Accepted Solution

by:
crazycomputers earned 50 total points
ID: 10743475
What you could do is something like this..

<?php

$_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July',
                           'August', 'September', 'October', 'November', 'December');

// Note that _months is zero-based...
$month = $_months[$month - 1];

?>
0
 
LVL 1

Expert Comment

by:noy_ipunk
ID: 10773245
Well, I would do it with smt like this :

$mth = 14;  //for example..skips december and go back to january

//you must fill in all the arguments if you want to make use of date function ;)
$month = date("F", mktime(0, 0, 0, $mth+1 , 0 ,0));  //plus 1 because month's array starts from 0

echo "month number is= $mth and month name is  $month ";

//result will be : month number is= 14 and month name is February
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now