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($da te , 'F');
$day = date_format($da te, 'd');
print"$month<br >";
print"$day<br>" ;
[/PHP]
3 2527
I am running PHP 5.2.1 on mac OS 10.4.8
Try this one
[php]echo date('l, F jS Y', strtotime($date ));[/php]
Ronald :cool:
Atli 5,058
Recognized Expert Expert
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($dat e, 0, 4));
$month = abs(substr($dat e, 5, 2));
$day = abs(substr($dat e, 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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 BY time asc
and I am getting this error message:
MySQL Error number: 1064: You have an error in your SQL syntax near 'ORDER BY time asc' at line 2
I added the "as time" in hopes it wasn't seeing the 'DATE_FORMAT()'field as the time field.
|
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
|
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 datetime),
'%m/%Y') from yo where id = 1" but the data returns incorrectly. For
example, the id 1 the time is '28-4-2004-4:11' once I ranthe query,
the return data is 04/2028. Looks like MySQL treated 28 as the year.
What can I do to make it...
|
by: Peter Olcott |
last post by:
www.halting-problem.com
|
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( '2006-10-09','%d%m%y');
Query OK
but in the out put it will be in the form of '2009-10-06' ie in the date field 20 is added
| |
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 give the error. If we change the %b to %m ,its worked as both local and web also .but i want the date in format of 06-feb-2007. What can i do for this .Please any one help to do that in web.
Thanks in Advance
Sang
|
by: laverdir |
last post by:
<?
$query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 .
".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 .
".najava, " . " DATE_FORMAT(" . $this->tabela3 . ".vrijeme_stavljanja,
'%e. %c. %Y. %k:%i') FROM " . $this->tabela3 . ", " . $this->tabela2 .
" AS xref WHERE " . $this->tabela3 . ".id=xref.spis_id AND
xref.vrsta_id=" . $this->DB->quote($vrsta) . " ORDER BY " .
$this->tabela3 . ".vrijeme_stavljanja DESC";
?>
|
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 get rid of the
error:
SELECT `email`, `raum`, DATE_FORMAT('date',`%c %d`) as date FROM
`logger`;
|
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 date_format(). I know that this is built in with PHP 5 but I need to know how to fix it without getting another error message saying that my cookies are disabled. Can anyone please help me?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |