dmccabe Posted January 18, 2010 Share Posted January 18, 2010 I havent done any php in a long time and I was never an expert at it when I did. I remember having particular problems with dates, calculations and storing dates in uk formats. So I am basically making an asset database and want to record things like date of purchase. Warranty expiration date etc. I will then want to create a report screen later that will allow us to view all items where the warranty expiration is due in the next X amount of months for example. The dates will be input on a form basis and in uk date format: DD/MM/YYYY So what type of field should I be using in the database to make this process easier? Link to comment https://forums.phpfreaks.com/topic/188896-how-best-to-store-dates-for-future-calculations/ Share on other sites More sharing options...
seavers Posted January 18, 2010 Share Posted January 18, 2010 I have read allot of other threads on this, and everyone likes to do things differently. Personally, I always store dates as a timestamp in the database, then convert them back using either the date() or the gmdate() php function. Being UK like me you will probably want to use gmdate() to get a Greenwich Mean Time date. Link to comment https://forums.phpfreaks.com/topic/188896-how-best-to-store-dates-for-future-calculations/#findComment-997419 Share on other sites More sharing options...
JonnoTheDev Posted January 18, 2010 Share Posted January 18, 2010 Store them using a DATE field. If you also require the time use a DATETIME. These field types make it much easier to write SQL to produce your reports allowing you to group by dates, etc. If you were to use a unix timestamp then querying is more difficult as you have to convert the timestamp back to date with FROM_TIMESTAMP. Dates will be formatted YYYY-MM-DD however it is so easy to convert them to UK format using your application code. Link to comment https://forums.phpfreaks.com/topic/188896-how-best-to-store-dates-for-future-calculations/#findComment-997428 Share on other sites More sharing options...
will35010 Posted January 18, 2010 Share Posted January 18, 2010 If you're going to be doing any calculations, I would store them as a timestamp. Otherwise date is fine. Link to comment https://forums.phpfreaks.com/topic/188896-how-best-to-store-dates-for-future-calculations/#findComment-997447 Share on other sites More sharing options...
fenway Posted January 18, 2010 Share Posted January 18, 2010 If you're going to be doing any calculations, I would store them as a timestamp. Otherwise date is fine. How is it any different? Link to comment https://forums.phpfreaks.com/topic/188896-how-best-to-store-dates-for-future-calculations/#findComment-997511 Share on other sites More sharing options...
will35010 Posted January 19, 2010 Share Posted January 19, 2010 If you're going to be doing any calculations, I would store them as a timestamp. Otherwise date is fine. How is it any different? I've always had to convert any dates into a timestamp before I could calculate anything based on that date without writing a lot of code. You have way more experience than me, but I just like to keep it simple. I'm sure you can do it both ways. I've just never seen a simple way of doing it without a timestamp. Link to comment https://forums.phpfreaks.com/topic/188896-how-best-to-store-dates-for-future-calculations/#findComment-998210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.