Jump to content

PHP, MySQL and Time...


Koobazaur

Recommended Posts

Hello,

 

I need to store some dates in my database for record keeping, checking expiration dates, comparing dates with today's date etc. So I have two choicse:

 

1. Use MySQL DATETIME type and then use strtotime() in PHP to convert it to Unix Timestamp and compare that with time()

 

2. Use MySQL TIMESTAMP and compare it with time(). Whenever display it, I would use date().

 

I was wondering if there is any real and established reason for chosing one over ther other. I think 2 would be a better choice because I am paranoid that strtotime() will screw up some time when convertying and having the value in timestamp means I can format it however I want with date instead of using what the MySQL formatting.

 

 

On another note, is there a way to retreive MySQL data in the same type as it is stored? I use mysql_query and then mysql_fetch_array($mysql_con, MYSQL_BOTH) but all the values in the returned array are strings (even those which are ints in the database)?

 

Oh and just to make sure - time() returns the timestamp from the server, not user? So a user won't be able to ovveride current time by changing his pc date, right?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/58811-php-mysql-and-time/
Share on other sites

Great I can't edit my post. Number 2 was supposed to be:

 

2. Use MySQL TIMESTAMP and compare it with time(). Whenever display it, I would use date().

 

 

I tried it and it turns out that TIMESTAMP stores it in a date format too, not a seconds value since 1970. Grrr... so I guess I would probably use INT instead of TIMESTAMP.

 

Link to comment
https://forums.phpfreaks.com/topic/58811-php-mysql-and-time/#findComment-291791
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.