Ask a Question related to ASP Database, Design and Development.
-
Tim::. #1
Datediff Problem
I am having some difficulties with the function Datediff! I am trying to calculate the number of days between two given date
E.G: Number days between 03-05-2004 and 05-05-2004 =
I am using the following piece of asp to extract dates from an XML document and work with them to create the above mentioned result, however I can't get it to work
Can someone please assist!
Thank
...::XML Exampl
<Project><ProjectID>1</ProjectID><Tasks><Task><TaskID>1</TaskID><Start></Start><Finish></Finish></Task><Task><TaskID>2</TaskID><Start></Start><Finish></Finish></Task></Tasks></Project
...:: AS
<
'Load XM
set xml = Server.CreateObject("Microsoft.XMLDOM"
xml.async = fals
xml.load(Server.MapPath("ProjectTEST.xml")
'Load XS
set xsl = Server.CreateObject("Microsoft.XMLDOM"
xsl.async = fals
xsl.load(Server.MapPath("GantChartView.xsl")
'Finds Start date in all Tasks in xml documen
Dim sNodes(200,100
Dim sDate(200,100
Dim sTime(200,100
Dim sMonth(200,100
Dim sDay(200,100
Dim fdw(200,100
node=-
var=-
set oNodes=xml.selectNodes("/Project/Tasks/Task/Start"
for each oNode in oNode
node=node+
for i=0 to 9
sNodes(node,i) = oNode.tex
nex
' Write whole data and time for Start of task as seen in XML Documen
'Break up date into different variable
var=var+
for i=0 to 9
sTemp = sNodes( node,0
sDate( var,i ) = Mid( sTemp, 1, 10
sTime( var,i ) = Mid( sTemp, 13, 4
sMonth( var,i ) = Mid( sTemp, 6, 2
sDay( var,i ) = Mid( sTemp, 9, 2
next
response.write "sDay " & (sDay(var,0)) & "<br>
'End Break up dates into variable
'Converts dates to beginning of week (Sunday
today = DateValue(sDate(var,0))
var=var+
for i=0 to 9
firstday = today + 1 - weekday(today, 1
fdw (var,i) = firstday
nex
FirstDayWeek = fdw (var,0
response.Write(fdw(var,0)
response.write(DateDiff("D", sDate(var,0), fdw(var,0))
next
Tim::. Guest
-
Datediff() bug
The Datediff("m",startdate,enddate) function does not return the correct value if the startdate is "2/28/05" and the enddate has a day value of... -
Query - Datediff problem
Hello all, I am trying to generate a list of users that have not responded to a survey in 3 months, but I am running into problems with the... -
DateDiff Problem with the Year 2000
I am having a problem calculating the proper age of people if they were born in the year 2000 <cfset bydate=#dateformat(#todaydate#,"mm/dd/yy")#>... -
DateDiff problem on different servers
I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to... -
DateDiff in C#
Hello, I am attempting to port some VB.NET code to C#.NET and have run across the DateDiff function in VB.NET. Does anyone know what the... -
Maarten #2
Re: Datediff Problem
In my country 2 is correct. Check the Format or the LCID
"Tim::." <anonymous@discussions.microsoft.com> schreef in bericht
news:BADE1DD7-5970-4015-B4F6-200FEFC9AEA9@microsoft.com...calculate the number of days between two given dates> I am having some difficulties with the function Datediff! I am trying todocument and work with them to create the above mentioned result, however I>
> E.G: Number days between 03-05-2004 and 05-05-2004 = 2
>
> I am using the following piece of asp to extract dates from an XML
can't get it to work.<Project><ProjectID>1</ProjectID><Tasks><Task><TaskID>1</TaskID><Start></Sta>
> Can someone please assist!
>
> Thanks
>
> ..::XML Example
>
rt><Finish></Finish></Task><Task><TaskID>2</TaskID><Start></Start><Finish></
Finish></Task></Tasks></Project>>
>
> ..:: ASP
> <%
> 'Load XML
> set xml = Server.CreateObject("Microsoft.XMLDOM")
> xml.async = false
> xml.load(Server.MapPath("ProjectTEST.xml"))
>
> 'Load XSL
> set xsl = Server.CreateObject("Microsoft.XMLDOM")
> xsl.async = false
> xsl.load(Server.MapPath("GantChartView.xsl"))
>
> 'Finds Start date in all Tasks in xml document
> Dim sNodes(200,100)
> Dim sDate(200,100)
> Dim sTime(200,100)
> Dim sMonth(200,100)
> Dim sDay(200,100)
> Dim fdw(200,100)
>
>
> node=-1
> var=-1
>
> set oNodes=xml.selectNodes("/Project/Tasks/Task/Start")
>
> for each oNode in oNodes
> node=node+1
> for i=0 to 99
> sNodes(node,i) = oNode.text
> next
>
> ' Write whole data and time for Start of task as seen in XML Document
>
> 'Break up date into different variables
> var=var+1
> for i=0 to 99
> sTemp = sNodes( node,0 )
> sDate( var,i ) = Mid( sTemp, 1, 10 )
> sTime( var,i ) = Mid( sTemp, 13, 4 )
> sMonth( var,i ) = Mid( sTemp, 6, 2 )
> sDay( var,i ) = Mid( sTemp, 9, 2 )
> next
>
> response.write "sDay " & (sDay(var,0)) & "<br>"
> 'End Break up dates into variables
>
>
> 'Converts dates to beginning of week (Sunday)
> today = DateValue(sDate(var,0))
> var=var+1
> for i=0 to 99
> firstday = today + 1 - weekday(today, 1)
> fdw (var,i) = firstday
>
> next
> FirstDayWeek = fdw (var,0)
> response.Write(fdw(var,0))
> response.write(DateDiff("D", sDate(var,0), fdw(var,0)) )
> next
Maarten Guest
-
drdagwood #3
DateDiff Problem
:o
Hello all,
this should be very simple but for some reason it's not. I've got two
dates that I want to find the difference between and to show the difference in
days. The whole thing is in a <cfoutput query=" "> tag. However, I keep
getting 365 as my answer even when there is less than a year between the two
dates. Can someone please take a gander at my code and make sure I'm not
missing something important.
Thanks,
D
<cfif pStatus IS "Rented">
<cfinvoke component="owner" method="listMiDate" returnvariable="getMiDate"
pID="#getPanelProperty.pID#">
<cfset MiDate = #DateFormat(getMiDate.miDate, "mm/dd/yyyy")#>
<cfset MoDate = #DateFormat(getMiDate.moDate, "mm/dd/yyyy")#>
<cfset LeaseTime = #DateDiff( "D", MiDate, MoDate)#>
<td><div align="center">#MiDate# | #MoDate# |#LeaseTime#</div></td>
<cfelse>
<td><div align="center">#rLeaseTime#</div></td>
</cfif>
drdagwood Guest
-
mxstu #4
Re: DateDiff Problem
Are you sure the problem is not your CFIF statement or a conflict with your
query? I ran a quick test and it returned the expected results:
output ---> 06/16/2005 | 06/30/2005 |14
<cfset getMIDate = structNew()>
<cfset getMIDate.miDate = createDate(2005, 6, 16)>
<cfset getMIDate.moDate = createDate(2005, 6, 30)>
<cfoutput>
<cfset MiDate = DateFormat(getMiDate.miDate, "mm/dd/yyyy")>
<cfset MoDate = DateFormat(getMiDate.moDate, "mm/dd/yyyy")>
<cfset LeaseTime = DateDiff( "D", MiDate, MoDate)>
<td><div align="center">#MiDate# | #MoDate# |#LeaseTime#</div></td>
</cfoutput>
mxstu Guest
-
drdagwood #5
Re: DateDiff Problem
It must have something to do with the query in which this code is located
within. That being the case let me show that code and maybe you can help me.
This code is supposed to get data from 2 tables that have the oID and pID
fields and then display it grouped together. That works fine, but then I only
want to show 10 properties at a time but show a next and back link to display
the next 10 properties or the last 10. The problem I'm having is that it when
I click the previous or next buttons the data isn't displayed as a group, only
parts of the data change, so I get numerous rows with the same properties but
with slightly different information from the other properties. If you can
please take a look and let me know what you think.
I'm thinking that this might be why I'm having the problem with the dates not
displaying properly because there is one property that should display 365 and
one that should display 296, but only the 365 is showing up for both properties.
Thanks,
D
Property Query:
<cffunction name="listPanelProperty" access="public" returntype="query">
<cfargument name="oID" required="yes" type="string">
<cflock timeout="10">
<cfquery datasource="#REQUEST.DataSource#" name="getPanelProperty">
SELECT *
FROM property, rent
WHERE property.oID = '#arguments.oID#' AND rent.oID = '#arguments.oID#'
ORDER BY property.pID
</cfquery>
</cflock>
<cfreturn getPanelProperty>
</cffunction>
Date Query:
<cffunction name="listMiDate" access="public" returntype="query">
<cfargument name="pID" type="string" required="true">
<cflock timeout="10">
<cfquery datasource="#REQUEST.DataSource#" name="getMiDate">
SELECT pID, miDate, moDate
FROM mimo
WHERE pID = '#arguments.pID#'
</cfquery>
</cflock>
<cfreturn getMiDate>
</cffunction>
Display Code:
<cfoutput query="getPanelProperty" group="pID" startrow="#start#"
maxrows="#end#">
<tr bgcolor="###iif(currentrow MOD 2,DE('ffffff'),DE('efefef'))#">
<td><div align="center"><a href="Show.cfm?pID=#pID#">#pID#</a></div></td>
<td><div align="center">NickName</div></td>
<td><div align="center">#pStatus#</div></td>
<td><div align="center">#DollarFormat(rAmount)#</div></td>
<cfif pStatus IS "Rented">
<cfinvoke component="owner" method="listMiDate" returnvariable="getMiDate"
pID="#getPanelProperty.pID#">
<cfset MiDate = #DateFormat(getMiDate.miDate, "mm/dd/yyyy")#>
<cfset MoDate = #DateFormat(getMiDate.moDate, "mm/dd/yyyy")#>
<cfset LeaseTime = #DateDiff( "D", MiDate, MoDate)#>
<td><div align="center">#LeaseTime# Days Remaining</div></td>
<cfelse>
<td><div align="center">#rLeaseTime#</div></td>
</cfif>
Next & Previous Code:
<!--- Start displaying with record 1 for property panel --->
<CFPARAM name="start" default="1">
<!--- Number of records to display on a page --->
<CFPARAM name="disp" default="10">
<CFSET end=Start + disp>
<CFIF start + disp GT getPanelProperty.RecordCount>
<CFSET end=999>
<CFELSE>
<CFSET end=disp>
</CFIF>
drdagwood Guest
-
drdagwood #6
Re: DateDiff Problem
Also,
I cut and pasted your code and it worked but when I changed the date format
to the one that I use mm, dd, yyyy it didn't work. Do I need to have my dates
in a particular format for the DateDiff to work?
D
drdagwood Guest
-
drdagwood #7
Re: DateDiff Problem
Well,
after all that I found out that it was a logic problem on my part. Sometimes it's the simple things.
Thanks,
D
:)
drdagwood Guest



Reply With Quote

