Hi there :)

I am doing a login log script and at first I didn't record the timestamp unlike all my newer logs, I was wondering is there a way to turn the date d/m/Y (15/02/2011) turned into a timestamp?

I would appreciate any help given
Thank you in advance!

Recommended Answers

Hi,

You can use mktime() to convert a date into a timestamp.
http://www.w3schools.com/php/func_date_mktime.asp

Jump to Post

All 4 Replies

How could I remove the forward slashes taken from the database column?

Member Avatar

If you're looking to replace the existing values with a timestamp, perhaps your best bet would be to create a new field called 'ts' (integer). Then create an update query that takes the value of your date field and transforms it into a timestamp and places it into ts. You can then delete the date field and rename the 'ts' field to whatever the date field was called - so that you don't break your php code and other queries.

"UPDATE table1 SET ts= UNIX_TIMESTAMP(STR_TO_DATE(datefield,'%d/%m/%Y'))"

I think that should work. If you want to try it, copy your table and try it on that, remembering to change the 'table1' in the sql to 'copy_of_table1' or to whatever you name it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.