NerdConcepts Posted October 4, 2007 Share Posted October 4, 2007 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 https://forums.phpfreaks.com/topic/71769-solved-date-issues/ Share on other sites More sharing options...
NerdConcepts Posted October 4, 2007 Author Share Posted October 4, 2007 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 https://forums.phpfreaks.com/topic/71769-solved-date-issues/#findComment-361438 Share on other sites More sharing options...
darkfreaks Posted October 4, 2007 Share Posted October 4, 2007 topic solved please Link to comment https://forums.phpfreaks.com/topic/71769-solved-date-issues/#findComment-361440 Share on other sites More sharing options...
NerdConcepts Posted October 4, 2007 Author Share Posted October 4, 2007 sorry, was getting to that, had a phone call and got side tracked. Link to comment https://forums.phpfreaks.com/topic/71769-solved-date-issues/#findComment-361441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.