473,325 Members | 2,785 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,325 software developers and data experts.

Formatting a date with php from a mysql table

Hello
I have date and time in my mysql table in the form
2007-05-03 00:00:00
which I have dispayed on my webpage using
echo $selldatetime
I want to know how I can display it in the form
03-05-2007

Thanks
Oct 27 '07 #1
3 1601
ok
I found it

echo date('d-m-Y', strtotime($selldatetime))

seems to work
"mantrid" <ia********@virgin.netwrote in message
news:4L***************@newsfe3-win.ntli.net...
Hello
I have date and time in my mysql table in the form
2007-05-03 00:00:00
which I have dispayed on my webpage using
echo $selldatetime
I want to know how I can display it in the form
03-05-2007

Thanks


Oct 27 '07 #2
..oO(mantrid)
>ok
I found it

echo date('d-m-Y', strtotime($selldatetime))

seems to work
It does, but often it makes more sense to let MySQL return an already
formatted date. Have a look at the DATE_FORMAT() function.

The main reason is that it avoids the conversion of the date to a Unix
timestamp. These timestamps are much more restricted in range (typically
1970-2038, back to 1902 with negative values) than MySQL timestamps and
should be avoided when they're not really necessary like in this case.

And just in case your script still has to work with Unix timestamps, the
DB can also do this conversion work for you with UNIX_TIMESTAMP(). I
would prefer that instead of a strtotime() call.

Micha
Oct 27 '07 #3
thanks Micheal
I will do the formatting in the sql statement as you suggest
Ian
"Michael Fesser" <ne*****@gmx.dewrote in message
news:8d********************************@4ax.com...
.oO(mantrid)
ok
I found it

echo date('d-m-Y', strtotime($selldatetime))

seems to work

It does, but often it makes more sense to let MySQL return an already
formatted date. Have a look at the DATE_FORMAT() function.

The main reason is that it avoids the conversion of the date to a Unix
timestamp. These timestamps are much more restricted in range (typically
1970-2038, back to 1902 with negative values) than MySQL timestamps and
should be avoided when they're not really necessary like in this case.

And just in case your script still has to work with Unix timestamps, the
DB can also do this conversion work for you with UNIX_TIMESTAMP(). I
would prefer that instead of a strtotime() call.

Micha

Oct 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RT | last post by:
If anyone can help that would be great. I¹m trying to format a timestamp from my MySQL table (sessions) Here¹s the code I¹m using: <?php echo date('D,n-j-y h:i:s...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
4
by: deko | last post by:
I've heard it's best not to have any formatting specified for Table fields (except perhaps Currency), and instead set the formatting in the Form or Report. But what about Yes/No fields? When I...
2
by: laredotornado | last post by:
Hello, Using PHP 4, MySQL 4, I am getting a date field $dbh = executeSQL($query); while ($row = mysql_fetch_array($dbh)) { $offer_id = $row; $dep_date = $row; // print out date print...
7
by: Middletree | last post by:
I am trying to display dates in a spreadsheet, but the dates need to be in a format that will allow them to be sorted in Excel. The datatype in the SQL Server database is datetime. In this case, I...
9
Tormod
by: Tormod | last post by:
I'm having problems formatting a date retrieved from mysql database. When I retrieve the date it's in the format YYYY-MM-DD. I need to split the Day, Month and Year portions of the date up so that I...
7
by: keeps21 | last post by:
I have a fixture list stored in a table, date, venue, opposition table consists of: id, date, venue, opposition. date is stored as a 'date' yyyy-mm-dd, what i want to do is ouput the table ...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.