Hi.
I'have this problem. I need of change a date like this 15/Aug/03 in a date like this 1039906800 and insert into Mysql: Can I do converter the dates?
thanks
Hi.
I'have this problem. I need of change a date like this 15/Aug/03 in a date like this 1039906800 and insert into Mysql: Can I do converter the dates?
thanks
Yup. That latter date looks an awful lot like a Unix timestamp ... assuming it is, there are two ways to accomplish the conversion: 1) Do it yourself with something like mktime(), or 2) let MySQL do it for you with UNIX_TIMESTAMP() .
Method #1:
$dString = '07/09/2003'; //day, month, year
$dArray = explode('/', $dString);
$date = mktime(0, 0, 0, $dArray[1], $dArray[0], $dArray[2]);
//make Unix timestamp for 00:00 07 Sept 2003
$query = "INSERT INTO dbName SET date=$date";
Method #2:
$dateString = '07/09/2003';
$ds = explode('/', $dateString);//create an array - in order day, month, year
$query = "INSERT INTO dbName SET date=UNIX_TIMESTAMP($ds[2]$ds[1]$ds[0])";
I'd prefer the second way, but either is alright ... just don't forget to make sure the day/month/year order is correct for whatever function you're using.
Sorry, but it don't work or I don't understand.
I have a form (in page1.php) with 20 text field compiled with 20 time date like 12/Sep/02 12:20, 06/May/03 22:50 etc. The form action is page2.php, where I would to change the time data of all text field (I write the time data manually) from 02/Jan/03 12:50 to correspondent Unix Timstamp (13254210) and update the mysql.
Can you post a script example for me? If you want more details, ask me! Thank'you verymouch!
I've already posted two example scripts - both of which work perfectly; I know I'm a lazy typer, so I tested them out for errors, etc, and they're fine.
It shouldn't take much effort to extrapolate them into scripts that fit your situation ... but here are a few pointers:
- If all your dates are hardcoded in the format 00/Month/0000 then you can use the date() function to format them into MySQL compatable dates (that is, YYYY-MM-DD).
- If you have many dates, they're probably in an array(if they're not, put them in one - it will save you a load of work). It's easy enough to iterate (loop) over the array and insert the dates into the database ... formatting each date properly as you go. I'm sure you're already familiar with the basic for, foreach, andwhile loops. They are designed specifically for this sort of task.