Solved

Formatting Dates example 01 - January

Posted on 2004-04-02
3
289 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
[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
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

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.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…

726 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