CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Datediff Function - Basic - Find diff between dates

Print topic Send  topic

Author Message
webtotaltoday

Posts: 46
Posted: 06/02/2006, 5:25 AM

Hi,

I am trying to find the difference between 2 dates in the URL.

I have this sql code:

select datediff ('{to}', '{from}') as total

But for somereason it gives the error

Database Error: You have an error in your SQL syntax near '('30/06/2006', '29/06/2006') as total LIMIT 0,1' at line 1

Can anyone help?

Regards
View profile  Send private message
mrachow


Posts: 509
Posted: 06/02/2006, 6:52 AM

I found right syntax should be
DATEDIFF ( datepart , startdate , enddate )
with day for datepart for example.
_________________
Best regards,
Michael
View profile  Send private message
webtotaltoday

Posts: 46
Posted: 06/02/2006, 8:36 AM

Hi,

I tried that but still errors.

I have changed it to PHP code and it works fine

But for some reason when it collects the data from the URL for the to and from date it puts it in a yyyy-mm-dd format rather than my URL format which is dd-mm-yyyy

Is there any way i can change this?

Here is the code:


$date1 = (CCGetFromGet("from", ""));
$date2 = (CCGetFromGet("to", ""));

$string1 = strtotime($date1); // or the variable $date1
$string2 = strtotime($date2); // or the variable $date2

// Subtract the difference
$difference = $string2-$string1;

// divide by the time period you wish to check

$DifferenceInDays = $difference/86400;

$orders->fullamount->SetValue($DifferenceInDays);
View profile  Send private message
WKempees
Posted: 06/03/2006, 4:21 AM

This works (result = 19)

select DATEDIFF('2006-05-30','2006-05-11') as total

1:So is your MySQL version 4.1.1+ ? That is when datediff() was added.
2:Is your dateformat for the database and project the same and correct?
You are feeding it dd/mm/yyyy it is expecting yyyy-mm-dd.
3: Maybe you just need to format the date you are getting from the URL into
the right (expected) fromat to make it work.

Walter



Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.