Jump to content

PHP Date Conversion


websteve

Recommended Posts

Thanks for the reply, but what if I want to display the converted data to the screen? I'm trying this code (below) that searches all rows between 2 dates, using STR_TO_DATE().  Doesn't seem to work correctly, but besides getting this to work right, the end result I want is to echo the converted date to the display.  Sorry for sounding confused, I used to work in PHP a few years ago and am just starting to get back into it.

 

This is the code I have now. I know it is not correct.

 

$datefilter = '%m/%d/%y/';

$Res_pur = "SELECT * FROM Purchasing WHERE Date BETWEEN STR_TO_DATE('$beg_date', '$datefilter') AND STR_TO_DATE('$end_date', '$datefilter')";

$Results_pur = mysql_query($Res_pur)or die('Could Not Access Purchasing Table: ' . mysql_error());

while ($Results_pur_Arr = mysql_fetch_array($Results_pur)) {

echo '<tr><td>'. $Results_pur_Arr['ID'] . '</td><td>'. $Results_pur_Arr['Date'].'</td><td>'. $Results_Arr['Item'].'</td><td>'.$Results_Arr['Description'].'</td></tr>';

}

Link to comment
Share on other sites

but what if I want to display the converted data to the screen?

 

Instead of using the wildcard * (which is never a good idea), specify the fields you want and use the DATE_FORMAT() function around your Date field.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.