Current location: Hot Scripts Forums » Programming Languages » PHP » date format mysql and php


date format mysql and php

Reply
  #1 (permalink)  
Old 07-19-06, 08:22 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
date format mysql and php

I am trying to display the date in the "l dS F Y" format on my web page for each entry in the database. I have found plenty of articles on how to change the format for todays date but not for the actual date entered in a field.

my database field is named date and is of type "date". the entered date is 0000-00-00 format. This is the code I am using to try and convert it for display on the web page:

PHP Code:

$connection mysql_connect($host,$usr,$pwd);

if (
$date) { $date_sql "and date LIKE '%$date%' "; }
if (
$venue) { $venue_sql "and venue LIKE '%$venue%' "; }

$query mysql_db_query($db"SELECT * FROM table_gigs where id > 0 $date_sql $venue_sql order by date desc"$connection);
check_mysql($query);
$filename "list_header.html"
$handle fopen ($filename"r"); 
$contents fread ($handlefilesize ($filename));
$contents str_replace(XrowsXmysql_num_rows($query), $contents);
print 
$contents;
fclose ($handle);


while (
$row mysql_fetch_array($query)) {
$date $row["date"];
$date date("l dS F Y"$date);  /* the bit in question */

$venue $row["venue"];
$id $row["id"];


$filename "list.html"
$handle fopen ($filename"r"); 
$contents fread ($handlefilesize ($filename));
$contents str_replace(Xgigs_titleX$gigs_title$contents);
$contents str_replace(Xheading_gigsX$heading_gigs$contents);
$contents str_replace(XdateX$date$contents);
$contents str_replace(XvenueX$venue$contents);
$contents str_replace(Xbutton1X$button1$contents);
$contents str_replace(Xbutton2X$button2$contents);
$contents str_replace(Xbutton3X$button3$contents);
$contents str_replace(Xbutton4X$button4$contents);
$contents str_replace(Xbutton5X$button5$contents);
$contents str_replace(XidX$id$contents);
print 
$contents;
fclose ($handle);

any ideas?
__________________
Aye!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-19-06, 08:39 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Try this.

PHP Code:

$date date("l dS F Y"strtotime($date) );  /* the bit in question */ 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-19-06, 09:08 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
The simple things! Genius once again. Thanks nico
__________________
Aye!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-27-08, 11:20 AM
amkma amkma is offline
New Member
 
Join Date: Oct 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
And what if the date field is empty. I mean 0000-00-00.

With the above solution it shows 30/11/1999 for me.

Any help please.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-27-08, 11:35 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Well, I tried the following
PHP Code:

$date "0000-00-00";
echo 
date("l dS F Y"strtotime($date) ); 
and as expected, I got the Unix epoch date
Code:
Thursday 01st January 1970
Even with the string set to nothing, I got the same result. How you came to get 30/11/1999 I'll never know. Very random
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-27-08, 12:04 PM
amkma amkma is offline
New Member
 
Join Date: Oct 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Can we get the result as 00/00/0000 instead?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-27-08, 12:23 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by amkma View Post
Can we get the result as 00/00/0000 instead?
Not using strtotime no, as it returns a unix time, so 0 will be 1/1/1970, as that is the start of the Unix epoch
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 03-27-08, 12:52 PM
amkma amkma is offline
New Member
 
Join Date: Oct 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
any alternative?
Or instead of 00/00/0000 can we get a blank result?

Regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 03-27-08, 02:42 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by amkma View Post
any alternative?
Or instead of 00/00/0000 can we get a blank result?

Regards
not if you use the strtotime function no. you will have to test for it seperately beforehand
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 03-28-08, 05:06 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
there's a very simple workaround: you just use an if!
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 04:06 AM
IIS MYSQL and PHP nommiiss PHP 6 01-31-06 05:30 PM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 09:03 PM
date format for mysql runya PHP 3 07-28-03 01:56 AM


All times are GMT -5. The time now is 12:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.