Jump to content

[SOLVED] Date issues


NerdConcepts

Recommended Posts

I've got a date that looks like this: 06/08/2007 AM

I'm trying to convert it to a MySQL acceptable date so it can be inserted into the data and read as normal MySQL dates would read so I can use my date searching functions. I use a lot of -30 days searches and stuff like that. As I insert the records into the database (which come in from a .csv file) the "SCHEDULED_DATE" looks like that above but that, as we all know, won't work with things like 'SCHEDULED_DATE > $onemonth' ($onemonth being a date that is a month ago). So while the records are imported I have been trying to take that date and convert it into a usable MySQL date. Although my attempts have completely failed. Here is one of the newest things I have used, which didn't work and I really don't know why.

 

(remember that this is a test so there is only one record in the database.)

$query = mysql_query("SELECT * FROM dn_records_data");
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
$x = $row['SCHEDULED_DATE'];

$bust = explode("/", $x); // Takes apart the date like at the top of this post that I showed...
$bust2 = explode(" ", $bust[2]); // Takes apart the '2007 AM' so I can take out the AM part
$newdate = $bust2[0] . '-' . $bust[0] . '-' . $bust[1]; // reformates 06/08/2007 AM to 2007-06-08 (like in MySQL)
$newdate = date($newdate); // I tried this to see if it needed the whole date thing.

$y = $row['WORK_ORDER_NUMBER']; // gets the work order number
$query2 = mysql_query("UPDATE work_orders SET wo_dn_scheduled_date='$x' WHERE wo_number='$y'"); // updates my information for work orders (since I don't modify the original imported data, it is stored for my records as it comes from my contractors)
}

 

I've tried this, no errors but when I check the database it shows '0000-00-00' for the wo_dn_scheduled_date. Not sure what to do here. BTW the scheduled date is almost always different then the date I insert the records into the database and because of that I can't just put todays date on there. Also note, my test records are old, lol.

Link to comment
Share on other sites

Ok, ok, right after I hit the "Post" button I noticed that I was inserting the original $x which is the messed up date not the new one. Once I changed the code to use the new date, it worked, lol. Yes, I'm blind sometimes.

 

should be:

$query2 = mysql_query("UPDATE work_orders SET wo_dn_scheduled_date='$newdate' WHERE wo_number='$y'");

 

not:

$query2 = mysql_query("UPDATE work_orders SET wo_dn_scheduled_date='$x' WHERE wo_number='$y'");

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.