Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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")#>...
    4. 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...
    5. 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...
  3. #2

    Default 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...
    > I am having some difficulties with the function Datediff! I am trying to
    calculate the number of days between two given dates
    >
    > 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
    document and work with them to create the above mentioned result, however I
    can't get it to work.
    >
    > Can someone please assist!
    >
    > Thanks
    >
    > ..::XML Example
    >
    <Project><ProjectID>1</ProjectID><Tasks><Task><TaskID>1</TaskID><Start></Sta
    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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default 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

  8. #7

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139