Sign in to follow this  
Followers 0
JusGellin

Problems With _DateDiff

3 posts in this topic

Shouldn't I be able to use variables as arguments in the _DateDiff function?<br>If I just put strings into the function, it works, but if I use variables, it doesn't. What am I doing wrong? Thanks

#include <Date.au3>
 Dim $startdate
 Dim $dropdate
; Calculated the number of Hours
 $startdate = "12/29/2007 1:38:51 AM"
 $dropdate = "2/17/2008 2:30:08 PM"
 
 $newstartdate = FormatDate($startdate)
 ConsoleWrite($newstartdate)
 
 $newdropdate = FormatDate($dropdate)
 ConsoleWrite($newdropdate)
 
;$hrs = _DateDiff('h', "2007/12/29 01:38:51", "2008/02/17 14:30:08"); works
;~ $newstartdate = "2007/12/29 01:38:51" ; works if variables set here
;~ $newdropdate = "2008/02/17 14:30:08"
 
 $hrs = _DateDiff('h', $newstartdate, $newdropdate)
 
 ConsoleWrite($hrs & @CRLF)
 
 Func FormatDate($dat)
    ; returns format for Auotit of yyyy/mm/dd hh:mm:ss from
    ;  log date of m/d/yyyy h:mm:ss am/pm
     $pattern = "[\d]?\d/[\d]?\d/(\d\d\d\d)"
     $year = StringRegExp($dat, $pattern, 1)
     
     $pattern = "[\d]?\d"
     $temp = StringRegExp($dat, $pattern, 1)
     $month = StringRight("0" & $temp[0], 2)
     
     $pattern = "[\d]?\d/([\d]?\d)"
     $temp = StringRegExp($dat, $pattern, 1)
     $day = StringRight("0" & $temp[0], 2)
 
     $pattern = " (\d)"
     $hr = StringRegExp($dat, $pattern, 1)
     $PM = StringRight($dat, 2)
     If $PM = "PM"  Then
         If $hr[0] < 12 Then
             $hr[0] += 12
         EndIf
     Else
         If $hr[0] = 12 Then
             $hr[0] = "00"
         EndIf
     EndIf
     $hr[0] = StringRight("0" & $hr[0], 2)
     
     $minsecs = StringRight($dat, 8)
     $minsecs = StringLeft($minsecs, 5)
 
     Return ($year[0] & "/" & $month & "/" & $day & " " & $hr[0] & ":" & $minsecs & @CRLF)
 
 EndFunc  ;==>FormatDate

Share this post


Link to post
Share on other sites



Your FormatDate function returns incorrectly formatted string (@CRLF at the end).


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Your FormatDate function returns incorrectly formatted string (@CRLF at the end).

Great! Thanks for the quick resolution. The @CRLF was used when I was testing using ConsoleWrite in the function. I forgot to take it out again. Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0