473,382 Members | 1,357 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,382 software developers and data experts.

date_format problem

I am trying to take a date in the format "YYYY-MM-DD" and get from it the month as a word (e.g. July) and the day as a 2 digit number (e.g. 24).

I am trying to use the date_format function, (new as of php 5.2) but I can't get it to work...

[PHP]
$date = "2007-06-22 00:00:00";
//I also tried $date = "2007-06-22"; but that didn't work either
//I also tried adding strtotime($date); but that didn't help!

$month = date_format($date , 'F');
$day = date_format($date, 'd');

print"$month<br>";
print"$day<br>";
[/PHP]
Feb 17 '07 #1
3 2506
I am running PHP 5.2.1 on mac OS 10.4.8
Feb 17 '07 #2
ronverdonk
4,258 Expert 4TB
Try this one
[php]echo date('l, F jS Y', strtotime($date ));[/php]

Ronald :cool:
Feb 18 '07 #3
Atli
5,058 Expert 4TB
Hi.

I modified you code so it returns to you the month as 3 letter word and the day as 2 digits, like this:
Sep 05

[PHP]
$date = "2007-06-22 00:00:00";

// get the parts you need from the string
// and turn them into numbers (abs)
$year = abs(substr($date, 0, 4));
$month = abs(substr($date, 5, 2));
$day = abs(substr($date, 8, 2));

// Create the output string
$output = date("M d", mktime(0, 0, 0,$month, $day, $year));

// print
print $output;
[/PHP]

You should check out the date and mktime methods at php.net

Hope this helps.
Feb 18 '07 #4

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

Similar topics

2
by: Rick | last post by:
I have been trying to run this MySQL query using PHP: SELECT id, trans_type, remote_addr, DATE_FORMAT(time, '%M %e, %Y %r') as time FROM transactions WHERE client_id = " . $client_id . " ORDER...
2
by: Johan den Boer | last post by:
Hi, What is wrong with this code ? SELECT DATE_FORMAT( myfield, GET_FORMAT( TIMESTAMP, 'EUR' ) ) FROM T_TABLE; regards Johan
0
by: Jimmy | last post by:
Hi, I'm new to MySQL and I have qustion regarding to CAST and Date_Format functions. I'm trying to convert a column 'Time' varchar(50) to datetime datatype by "select date_format(cast(time as...
117
by: Peter Olcott | last post by:
www.halting-problem.com
3
by: sang | last post by:
Hai I want to change the date format at the time of inserting the record. i done it but one error in the insertion. The query is insert into mytable(update) values(date_format(...
1
by: sang | last post by:
Hi In my table the date format is changed to 06-feb-2007.The query i execute is select date_format(col.name,"%e-%b-%Y") from tablename; This is worked well in local but in the web it will...
16
by: laverdir | last post by:
<? $query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 . ".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 . ".najava, " . " DATE_FORMAT(" . $this->tabela3 ....
2
by: docscsi | last post by:
Dear all I'm quite new to mysql. My aim is to select a date format field by returning only the month and day number of it (e.g. date = 11 12). I got this statement and I could not get out how to...
2
by: ann86 | last post by:
Hello, I am a newbie to PHP and I am working on a site that was created by someone else. The server was updated yesterday so now I am getting the error Fatal error: Cannot redeclare...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.