Convert String to Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
potain
Forum Newbie
Posts: 2
Joined: Sun May 31, 2009 9:23 am

Convert String to Date

Post by potain »

Hi

I am new to the forum which I found accidentally just now and I am all exited.

Can I ask you first of all what version of phpBB the forum uses as I haven't seen this setup before?

I am a php novice and a program that I am using writes four values to a MySql database the last being "joindate" using now() in a date fiekl and the records are retrieved looping through an array into a list. The date text is in US format and I want to change it to D j M Y. I have tried this but it does not work. Any help would be greatly appreciated:
$r = mysql_query ("SELECT SQL_CALC_FOUND_ROWS id FROM $table ORDER BY login LIMIT $xlimit,$ylimit;");
$r1 = mysql_query("SELECT FOUND_ROWS() as total;");
$f1 = mysql_fetch_assoc($r1);
$r_rows = mysql_num_rows($r);
for ($x=0;$x<$r_rows;$x++){
$f = mysql_fetch_assoc($r);
$user_list[$x][id] = $f[id];
$rb = mysql_query("SELECT id FROM $table_list WHERE userid='$f[id]';");
for($xb=0;$xb<mysql_num_rows($rb);$xb++){
$fb = mysql_fetch_assoc($rb);
$user_listing[$f[id]][$xb] = $fb[id];

$fb["joindate"]= date("D j M Y", strtotime($datestring));

}
$user_list[$x][listing_count] = count($user_listing[$f[id]]);
}
Thank you in advance.
kcormier
Forum Newbie
Posts: 11
Joined: Sun May 31, 2009 1:36 am

Re: Convert String to Date

Post by kcormier »

can you give us a sample of what the join date looks like after your script runs?

plus what is the value in datestring?

If the value is just now() why even bother with the datestring variable?

/edit - proper indentation of code helps too

Code: Select all

 
$r = mysql_query ("SELECT SQL_CALC_FOUND_ROWS id FROM $table ORDER BY login LIMIT $xlimit,$ylimit;");
$r1 = mysql_query("SELECT FOUND_ROWS() as total;");
$f1 = mysql_fetch_assoc($r1);
$r_rows = mysql_num_rows($r);
for ($x=0;$x<$r_rows;$x++){
    $f = mysql_fetch_assoc($r);
    $user_list[$x][id] = $f[id];
    $rb = mysql_query("SELECT id FROM $table_list WHERE userid='$f[id]';");
    for($xb=0;$xb<mysql_num_rows($rb);$xb++){
        $fb = mysql_fetch_assoc($rb);
        $user_listing[$f[id]][$xb] = $fb[id];
 
        $fb["joindate"]= date("D j M Y", strtotime($datestring));
 
  }
  $user_list[$x][listing_count] = count($user_listing[$f[id]]);
}
 
potain
Forum Newbie
Posts: 2
Joined: Sun May 31, 2009 9:23 am

Re: Convert String to Date

Post by potain »

Hi kcormier

Thanks for your prompt reply.

Here is what the field looks like after the script runs:
"User login" "User ID" Joined: 2009-06-23
"User Mail"

With datestring, I thought that it was part of the strtotime function so I don't know what the value is or if I need to declare it first. Without it php gives me this error:

Warning: date() expects parameter 2 to be long, string given in g:\xampp\,,,,\user.php line 548 which corresponds to the function.

Sorry about the indentation.
Post Reply