Converting (mysql format) DAYS to timestamp..
Moderator: General Moderators
Converting (mysql format) DAYS to timestamp..
A friend is trying to use Day number, ala MySQL does, and wants to convert format using date()
i.e. he has an integer which is the number of days since 1st Jan 1A.D. e.g. 732889 is Tuesday 1st August 2006.
however.. there is no table interaction and there is 000's of iterations, as such using mysql_query() to calculate it is a no-no at the moment.
Does anyone know of a function to convert this to unix timestamp?
i.e. he has an integer which is the number of days since 1st Jan 1A.D. e.g. 732889 is Tuesday 1st August 2006.
however.. there is no table interaction and there is 000's of iterations, as such using mysql_query() to calculate it is a no-no at the moment.
Does anyone know of a function to convert this to unix timestamp?
That's what we have been 'discussing' for the last 45mins, me trying to convince him to retrieve the data as a timestamp in the first place.
However he is adamant there is no interaction with the DB for it, which leaves me wondering where the number comes from..
Either way he has just succumbed and will be using unix timestamp and work in seconds instead.
However he is adamant there is no interaction with the DB for it, which leaves me wondering where the number comes from..
Either way he has just succumbed and will be using unix timestamp and work in seconds instead.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
There is a possibility of using strtotime() where you take the TO_DAYS() of the Epoch, diff the two then tell strtotime to give you the date from the epoch... ..that is if strtotime() wants to play nice. You could pick a date further into the future (from the epoch that is.)
Code: Select all
mysql> select to_days(from_unixtime(0));
+---------------------------+
| to_days(from_unixtime(0)) |
+---------------------------+
| 719527 |
+---------------------------+
1 row in set (0.06 sec)Thanks, I'm messing around with that now. However, when I run as you did above.. I get:
Code: Select all
mysql> select to_days(from_unixtime(0));
+---------------------------+
| to_days(from_unixtime(0)) |
+---------------------------+
| 719528 |
+---------------------------+
1 row in set (0.00 sec)maybe http://de2.php.net/calendar is of interest
I am that friend
Thank you all very much for all your help, comments and links.
I was just trying to get a "day number" expressed as an integer for any given date YYYY-mm-dd and to be able to switch between date and "day number" / "day number" and date at any time.. either using php or mysql and stumbled across the TO_DAYS and FROM_DAYS mysql - and thought this might give me what I need...
I think I have enough info now from your comments to be able to achieve what I need, so am going to chuck myself back into the various manuals and testing server for a bit
Much appreciated
I was just trying to get a "day number" expressed as an integer for any given date YYYY-mm-dd and to be able to switch between date and "day number" / "day number" and date at any time.. either using php or mysql and stumbled across the TO_DAYS and FROM_DAYS mysql - and thought this might give me what I need...
I think I have enough info now from your comments to be able to achieve what I need, so am going to chuck myself back into the various manuals and testing server for a bit
Much appreciated