Jump to content

Recommended Posts

I have a MySQL field 'orgDateAmended'

 

I need to obtain the number of days since the record was amended in PHP.

 

In plain english  [currentdate] - [orgDateAmended] = x  << i want 'x'

 

I have no issue retrieving the date in MySQL, I just need to know how to subtract the two once I have the orgDateAmended assigned to a PHP Variable.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/171852-subtract-two-dates-and-get-an-integer/
Share on other sites

Is it not easier to do it in PHP with PHP functions?

 

That actually doesn't matter but given you are retrieving the data from MySQL you might aswell do the conversion in your query so that you can start working with it in PHP

Ok, I get an integer (74891990) from now()-date_amended, which I presumed was seconds, but with a date of 2009-08-27 23:22:18, now()-this date should result in approx  483,304.79 seconds (8055 mins or 134 hrs or 5.59 days). 

 

If 74891990 were seconds, it would result in 866 days, ie: way out.

 

Can someone explain why I'm getting this figure and give me a hint where I'm going wrong please.

 

Thanks

 

A - DATETIME

B - Someone on another forum has provided the following solution:

 

UNIX_TIMESTAMP() - UNIX_TIMESTAMP(orgDateAmended) AS x

 

which appears to work just fine, unless you can see any issues with doing it this way?

 

Thanks

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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