Forum Moderators: coopster

Message Too Old, No Replies

difference between two dates

How to get number of days between a date in db and current date

         

Mitch888

6:19 pm on Apr 14, 2003 (gmt 0)

10+ Year Member



hi,
I am trying to get the number of days between a fixed date "$date_joined" and current date?

$ndays = $date_joined - 'now()'

how can i get the above statement working

wruk999

6:32 pm on Apr 14, 2003 (gmt 0)

10+ Year Member



Hi Mitch888,

If you can get the two dates in the same format and in $variables, then you can use the Arithmetic Operators [php.net] built into PHP.
Take a look through the PHP manual page above, and see what the best way to do it is. Maybe it is that you need the date formats in a way that are the same so that you can just use the subtraction and get the correct amount of days.

Regards,
wruk999

Jocelyn

6:45 pm on Apr 14, 2003 (gmt 0)

10+ Year Member



If you prefer to do it with MySQL (i.e. because you need to sort by number of days since user joined), you may find that page useful:
[mysql.com...]

Jocelyn

jatar_k

6:55 pm on Apr 14, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I do all of my date math by converting all dates to unix timestamps using mktime [php.net].

Once the math is done you can then use strftime [php.net] to convert into what ever form you would like.

lorax

7:07 pm on Apr 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does the fixed date come from a MySQL database query? If so you should check out Date and Time Functions [mysql.com]

Mitch888

6:35 pm on Apr 17, 2003 (gmt 0)

10+ Year Member



that did it. so many ways.. thanks :)