473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

php string to date conversion?

nirmalsingh
218 100+
i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
Apr 9 '07 #1
3 19254
dzuse
2
i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
I have one way how to do it, its long but for me it works ;)
i hope it will work for u!
input is 2007-04-09 and output is 09-April-2007
php code is [php]<?php
$date = "2007-04-09";
$explodedate = explode("-", $date);
$year = $explodedate[0];
$month = $explodedate[1];
$day = $explodedate[2];
if ($month == 01) { $month1 = 'Jan'; }
if ($month == 02) { $month1 = 'Feb'; }
if ($month == 03) { $month1 = 'Mar'; }
if ($month == 04) { $month1 = 'April'; }
if ($month == 05) { $month1 = 'may'; }
if ($month == 06) { $month1 = 'Jun'; }
if ($month == 07) { $month1 = 'Jul'; }
if ($month == 08) { $month1 = 'Aug'; }
if ($month == 09) { $month1 = 'Sep'; }
if ($month == 10) { $month1 = 'Oct'; }
if ($month == 11) { $month1 = 'Nov'; }
if ($month == 12) { $month1 = 'Dec'; }
echo $day."-".$month1."-".$year;
?>[/php]

Please encode any code within the appropriate code tags, See the Posting guidelines before you continue posting in this forum - moderator
Apr 9 '07 #2
this might work a little faster[php]function buildDate( &$date )
{
$explodedate = explode( "-", $date );
$year = $explodedate[0];
$month = $explodedate[1];
$day = $explodedate[2];

$months = array( '01' => 'Jan' , '02' => 'Feb' , '03' => 'Mar' , '04' => 'April' , '05' => 'May' , '06' => 'June' , '07' => 'July' , '08' => 'Aug' , '09' => 'Sept' , '10' => 'Oct' , '11' => 'Nov' , '12' => 'Dec' );

foreach( $months as $key => $value ){
if ( $key == $month ){
$month = $value;
break;
}
}

echo $day.'-'.$month.'-'.$year;
}[/php]

Please encode any code within the appropriate code tags, See the Posting guidelines before you continue posting in this forum - moderator
Feb 28 '08 #3
ronverdonk
4,258 Expert 4TB
i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
The fastest of them all, using the most simple solution using 2 PHP commands:[php]<?php
echo date('j-F-Y',strtotime('2007-04-09'));
?>[/php]Ronald
Feb 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
1
by: jwf | last post by:
This question continues on from a previous post "DATE to string" but I think it deserves a new thread. In my previous post I was trying to convert a DATE to string in a NON MFC C++ application...
5
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
4
by: Phillip Vong | last post by:
VS2005 in VB.NET I have 2 simple textboxes (Textbox1, Textbox2) and they both have dates. Textbox1=12/31/2006 Textbox2=12/15/2006 I need to convert these two textboxes that are in String...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
2
by: Chris H | last post by:
Hi, I'm trying to concatenate a Description (nchar(100)) and Date (datetime) as Description and my initial effort was just "...description+' '+open_date as description..." which throws a date/...
2
by: RN1 | last post by:
A TextBox displays the current date (in dd/mm/yyyy format) & time when a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the date into international format so that the remote server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.