PDA

View Full Version : MySQL Help Please!


mlangston
05-15-2003, 09:47 PM
I am very new to PHP/MySQL and I want to do a simple SQL statement on a page to calculate the difference in 2 dates and return the number of days remaining. In T-SQL I would say

DateDiff("d",Now(),"04/15/2004")

Is there an equivilent statement in MySQL? All the examples I have seen are very long & arduous code.

Thank you in advance for your help.

Mary Beth

raf
05-15-2003, 10:14 PM
Welcome here.

Is that T-SQL? Looks like VBscript to me.

Anyway, this is very short and good info on datacaculation with MySQL
http://www.mysql.com/doc/en/Date_calculations.html

I don't know which dateformat you use.
Do you want to compute the datadifference for two values (using PHP or ASP) or for all records in a db (using MySQL)?

mlangston
05-15-2003, 10:49 PM
Well, I did it both ways T-SQL & vbScript & copied the vbScript.

I want to compute the difference in the current date & 4/15/2004 to show how many days remain before Tax deadline.

raf
05-15-2003, 11:03 PM
Confusing!

Why do you need sql? None of these values come from the db (or maybe the 04/15/2004) so you can just do this in asp or php.
Also, MySQL doesn't allow you to store dates in that format.

In VB script, this would be

DateDiff("d",Now,rsRecordsetname.Fields("datevariable"))

rsRecordsetname.Fields("datevariable") is the value you pull from the db (need to change the recordsetname and variablename of coarse)

mlangston
05-16-2003, 01:32 AM
I apologize for the confusion. The web server that the site is hosted does not support .asp so vbScript is not an option. I need something that I can code in PHP, so since I know very little about PHP/MySQL I just need an equivilent code to put on my PHP page.

I hope that this makes more sense. Once again sorry for the confusion.

raf
05-16-2003, 07:32 AM
Doesn't seem to be a build in php-function for that.
This is what i found on the php site
-------------------
m0sh3NO at SPAMhotmail dot com
13-Feb-2002 06:29
- I use this function to get difference between 2 dates:

function date_diff($date1, $date2) {
_$s = strtotime($date2)-strtotime($date1);
_$d = intval($s/86400);
_$s -= $d*86400;
_$h = intval($s/3600);
_$s -= $h*3600;
_$m = intval($s/60);
_$s -= $m*60;
_return array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s);
}

Any better solutions?
---------------------------

But you could always try her at the php forum ...

mlangston
05-16-2003, 03:16 PM
Thank you for all your help. I was able to cull out some of the code you gave me to accomplish what I need. I truly appreciate the help.

Jeewhizz
05-21-2003, 01:45 AM
I'll move this to the PHP forum so future users can find it easier :)

<opens up mod gun>

Jee