DateDiff returning minus values

Results 1 to 2 of 2

Thread: DateDiff returning minus values

  1. #1
    Join Date
    Dec 1969

    Default DateDiff returning minus values

    Hi,<BR><BR>I&#039;m using the following code to work out the time difference between a date/time entry in a sql database and the current time.<BR><BR>The problem i&#039;m having is that it is returning minus values. i.e. should be 1 day but gives -1 day.<BR><BR>Dim dateregistered As DateTime = DsViewProblem1.problems.Rows(0).Item("problemdate" )<BR><BR>If DateDiff("d", Now, dateregistered) = 0 Then<BR> If DateDiff("h", Now, dateregistered) = 0 Then<BR> lblActiveFor.Text = DateDiff("n", Now, dateregistered) & " minutes"<BR> Else<BR> lblActiveFor.Text = DateDiff("h", Now, dateregistered) & " hours"<BR> End If<BR>Else<BR> lblActiveFor.Text = DateDiff("d", Now, dateregistered) & " days"<BR>End If<BR><BR>Is there anything obvious wrong with the above? Is there a better way of doing this?<BR><BR>Regards,<BR><BR>Robert<BR>

  2. #2
    Join Date
    Dec 1969

    Default Switch the values.

    DateDiff("d", dateregistered, Now)

Posting Permissions

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