|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Stuck with dates
Hi guys
I really don't understand datetime columns in Mysql or do I know where to start when it comes to php. Can anyone get me started with possible a php snibblit of code that takes two datetime fields in MySql and gives me average of time between the to columns. |
|
#2
|
|||
|
|||
|
RE: Stuck with dates
Quote:
Now, for what you would like to accomplish, I would use a timestamp field in mysql instead. I say this because it stores the information as a unix timestamp, and can easily be added and subtracted to. A unix timestamp is how many seconds it has been since January 1st, 1970. You can utilize the time() function when you want to generate a timestamp on the current time, date. If you need a custom timestamp, you can make one with the function mktime. I recommend using this over the datetime format, because there is a lot less work involved in using it, and because you are new to php, it would be a little better for you to "cut your teeth" on. |
|
#3
|
|||
|
|||
|
RE: Stuck with dates
working with time in php might get a little more in depth
i agree with nawlej. however, if you need it working NOW (and you WILL fix it later) you can always use a mysql function Code:
SELECT UNIX_TIMESTAMP(YOUR_DATE_COLUMN) AS CUSTOM_NAME FROM YOUR_TABLE then you can refer to it in php (assuming you do the intermediate steps) as |
|
#4
|
|||||
|
|||||
|
RE: Stuck with dates
O.k. I am almost there.
php Code:
then I do a quick division sum / (rows returned) and I have an average. Now my only problem is, as an example how do I convert 120 seconds into 02:00 minutes from the unix_time stamp??? |
|
#5
|
|||
|
|||
|
RE: Stuck with dates
O.k. got it Thought I would post it. someone might need this or could mod it for their own use.
Created this function so that you can pass it a average number of seconds. Once you have your unix seconds, say 120 send that number to this function and it will return it all nice and tidey in minute:second look and feel. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Stuck with dates |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|