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
Solved

Formatting Dates example 01 - January

Posted on 2004-04-02
3
288 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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.  …
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

809 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