Current location: Hot Scripts Forums » Programming Languages » PHP » converting date error


converting date error

Reply
  #1 (permalink)  
Old 03-20-04, 04:46 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
converting date error

hi,

im made a news programs and i wanted to convert the mysql to the regular format. so i found a code that would work and it gives me a parse error. heres that code:

PHP Code:

        while ($row mysql_fetch_array ($queryMYSQL_ASSOC)) {

list(
$year,$month,$day)= split('[/.-]', {$row['Date']});
$newdate =date("m-j-Y"mktime(000$month$day$year));
echo 
"<CENTER>";
echo 
"<B>{$row['Subject']}</B> -Posted By: <A HREF=\"/MetalPass/Viewprofile.php?user={$row['Username']}\">{$row['Username']}</A> on $newdate<BR><BR>";
echo 
"{$row['Body']}";
echo 
"<BR><BR><HR width=\"395\"><BR>";

please help me so i can get this working.thx.
__________________
Elite Bulletin Board
http://elite-board.us
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 03-21-04, 11:59 AM
IWeb IWeb is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
On what line does the error appear?

perhaps this line should be:
PHP Code:

list($year,$month,$day)= split("\-"$row['Date']); 

__________________
- PowerPPS PPS/PPC script
- Earn money
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 03-21-04, 12:12 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
actually its on the line you just wrote but acorrding to php.net the way i did it is correct. thats why im upset about this :@
__________________
Elite Bulletin Board
http://elite-board.us
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-21-04, 02:58 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

PHP Code:

list($year,$month,$day)= split('[/.-]', {$row['Date']}); 

Why are there curly braces around $row['Date']? Take them out and see what happens:

PHP Code:

list($year,$month,$day)= split('[/.-]'$row['Date']); 

Also another tip is that, if you know there is always going to be one and only delimiter (e.g. "/"), you could use explode() instead, which is faster.

HTH.
__________________
Blavv =|
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-21-04, 04:49 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
well i believe they belong on there. the rest of my code has that and it works fine. ill give it a try though also ill give the explode() a try too thx.
__________________
Elite Bulletin Board
http://elite-board.us
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-21-04, 06:06 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Okay, let me try...

PHP Code:

<?php


// For this test, assign a string value of yyyy/mm/dd .
$row['Date'] = '2003/03/22';

// From your code.
list($year,$month,$day)= split('[/.-]', {$row['Date']});
$newdate =date("m-j-Y"mktime(000$month$day$year));

// For this test, echo it.
echo $newdate;

?>
The following gives me this error, which I guess is more or less the same as yours:

Code:
Parse error: parse error, unexpected '{' in e:\web\foo\test.php on line 7
This means that "{" on line 7 is not supposed to be there.

But without "{" and "}", like this:

PHP Code:

<?php


// For this test, assign a string value of yyyy/mm/dd .
$row['Date'] = '2003/03/22';

// From your code, without "{" and "}" around $row['Date']
list($year,$month,$day)= split('[/.-]'$row['Date']);
$newdate =date("m-j-Y"mktime(000$month$day$year));

// For this test, echo it.
echo $newdate;

?>
I get this:

Code:
03-22-2003
I guess this is what you wanted. There shouldn't be any code block there. The rest of your code works with "{" and "}" around variables because you are using it to indicate "this is a variable" to PHP within double-quotations (i.e. string). You could, thus, double-quote it like so:

PHP Code:

list($year,$month,$day)= split('[/.-]'"{$row['Date']}"); 

This would give you the same output as the one before, but unless you have to concatenate something else to your $row['Date'], all it does is add 4 more unnecessary characters to your code - it makes a bit harder to read the code, too.

HTH.
__________________
Blavv =|
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-22-04, 03:49 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
hi,

i forgot to post that i gave your suggestion a test and it works now thx blaw, if you want i got another problem with it now,if you want to help me view the post i added yesterday
__________________
Elite Bulletin Board
http://elite-board.us
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
New to Java: weird main error msg hecresper Everything Java 2 02-10-04 04:03 PM
parse error... help? kappler0 PHP 2 01-21-04 04:57 AM
Urgent converting String to Date yymae Everything Java 1 01-16-04 12:22 PM
[php error] parse error | fatal error xeoHosting PHP 1 01-03-04 09:12 PM
Error: Syntax error converting datetime from character string. Han84 ASP 1 08-22-03 05:59 AM


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