Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Convert filetime to Julian date


phishguy Nov 21, 2012 11:36 PM

I have a routine to convert realtime to a Julian date (YYYYDOY). Is there a way to convert Filetime to a Julian date?


Sam Nov 22, 2012 04:16 AM

I haven't done much in the way of testing, but the following might help.

Public FTime As Long
Public Result As String

Function YYYYDOY(SS1990 As Long) As String
Dim DaysPerMonth(13) = {0,31,59,90,120,151,181,212,243,273,304,334}
Dim DateString As String 'YYYY-MM-DD HH:MM:SS.uu
Dim Ary(3) As Long 'YYYY, MM, DD
Dim DOY As Long 'day of year

DateString = SecsSince1990 (SS1990,4) 'convert SS1990 to YYYY-MM-DD HH:MM:SS.uu
SplitStr (Ary(),DateString,"-",3,5) 'split string date into YYYY, MM, DD
DOY = Ary(3) + DaysPerMonth(Ary(2)) 'days into month + num days already this year
If ((Ary(1) MOD 4 = 0) AND (Ary(1) MOD 100 <> 0) OR (Ary(1) MOD 400 = 0)) Then
'it's a leap year: divisible by 4 but not by 100, except when also divisible by 400
If Ary(2) > 2 Then
'march or later, add 1 day
DOY = DOY + 1
EndIf
EndIf

Return Ary(1) & FormatLong(DOY,"%03i")
EndFunction

BeginProg
Scan (1,Sec,0,0)
FTime = FileTime ("USR:myFile.dat")
'FTime = Public.Timestamp(1,1)
Result = YYYYDOY(FTime)

NextScan
EndProg


Sam Nov 23, 2012 04:47 AM

Testing looks good. Simulated a century and compared to realtime() results


phishguy Nov 26, 2012 07:56 PM

OK, I can't seem to get it to work in my program. I must be doing something wrong. I just can't figure out what. I get completely screwy values for the result.


Public PTemp, batt_volt, tempc
Dim N,fc
Public result As String
Public olddoy As String
Public FTime As Long
Dim crlf As String, char

'TABLE FILE DECLARATIONS
Public OutStat As Boolean
Public LastFileName As String * 40
Public InString As String * 300

'SERVER DECLARATIONS
Const Host = "ftp.host.org"
Const User = "rclark"
Const Pass = "Password"
Const RDir = "/home/rclark/"
Public LName As String * 40
Public RName As String * 40
Public Success As Boolean

'FILE QUEUE DECLARATIONS
Public NFile
Const QL = 10 'queue buffer size
Public Queue(QL) As String * 40

'Public year_date As Long
Const NL = 40 'this must match the length of the strings being passed into array
Const NF = 10

'real time table
Public rTime(9) 'declare as public and dimension rTime to 9

Alias rTime(1) = Year 'assign the alias Year to rTime(1)
Alias rTime(2) = Month 'assign the alias Month to rTime(2)
Alias rTime(3) = DOM 'assign the alias Day to rTime(3)
Alias rTime(4) = Hour 'assign the alias Hour to rTime(4)
Alias rTime(5) = Minute 'assign the alias Minute to rTime(5)
Alias rTime(6) = Second 'assign the alias Second to rTime(6)
Alias rTime(7) = uSecond 'assign the alias uSecond to rTime(7)
Alias rTime(8) = WeekDay 'assign the alias WeekDay to rTime(8)
Alias rTime(9) = Day_of_Year 'assign the alias Day_of_Year to rTime(9)

Public date As String * 25 'this will be year:month:day
Public time As String * 25 'this will be hour:min:sec:usec

Function YYYYDOY(SS1990 As Long) As String
Dim DaysPerMonth(13) = {0,31,59,90,120,151,181,212,243,273,304,334}
Dim DateString As String 'YYYY-MM-DD HH:MM:SS.uu
Dim Ary(10) As Long 'YYYY, MM, DD
Dim DOY As Long 'day of year

DateString = SecsSince1990 (SS1990,4) 'convert SS1990 to YYYY-MM-DD HH:MM:SS.uu
SplitStr (Ary(),DateString,"-",3,5) 'split string date into YYYY, MM, DD
DOY = Ary(3) + DaysPerMonth(Ary(2)) 'days into month + num days already this year
If ((Ary(1) MOD 4 = 0) AND (Ary(1) MOD 100 <> 0) OR (Ary(1) MOD 400 = 0)) Then
'it's a leap year: divisible by 4 but not by 100, except when also divisible by 400
If Ary(2) > 2 Then
'march or later, add 1 day
DOY = DOY + 1
EndIf
EndIf
return ary(1) & formatlong(DOY,"%03d")

end Function

'DATA TABLES
DataTable (Test,1,-1)
TableFile ("CRD:Test_",1,-1,0,1,MIN,OutStat,LastFileName)
Sample(1,date,String)
Sample(1,time,String)
Sample (1,tempc,FP2)
Sample(1,InString,String)
EndTable

'MAIN PROGRAM
BeginProg
PanelTemp (PTemp,250)
crlf = CHR(13)&CHR(10)
'SetStatus("USRDriveSize",1000000)
ResetTable(test)
SerialOpen (comrs232,57600,3,0,5000)
Scan (1,Sec,0,0)
While SerialInChk(comrs232)
SerialIn (InString,comrs232,0,crlf,300)
If Len(InString) > 0 Then
RealTime(rTime)

TCDiff (tempc,1,mV2_5,1,TypeT,PTemp,True ,0,250,1.0,0)

' Therm107(TempC,1,1,Vx1,0,250,1.0,0)
date=rTime(1) & "/" & FormatLong(rTime(2),"%02d") _
& "/" & FormatLong(rTime(3),"%02d")
time= FormatLong(Hour,"%02d") & ":" _
& FormatLong(Minute,"%02d") & ":" _
& FormatLong(Second,"%02d") & ":" _
& FormatLong(uSecond / 10000,"%02d")
CallTable test ' Record all received data
EndIf
Wend
NextScan

SlowSequence

Do While TRUE
' RealTime(rTime)
' If Minute = 15 Then
NFile = FileList("CRD",Queue())

If NFile > 0 Then
For N = 1 To NFile
fc += 1
LName = Queue(N)
FTime = FileTime(Queue(N))
result = YYYYDOY(ftime)
RName = RDir + Replace (Queue(N),"CRD:Test",result)
If result <> olddoy Then
fc = 1
olddoy = result
end If
RName = Left(RName,Len(RDir)+8) & fc
Success = FALSE
Success = FTPClient (Host,User,Pass,LName,RName,2) 'attempt to ftp

Delay (1,10,Sec) 'pause after attempt, yes this is a good idea
If Success Then
' ResetTable(test)
FileManage (Queue(N),8 ) 'remove file from drive
Else
ExitFor 'exit and try later
EndIf
Next N
' EndIf
Delay (1,20,Sec) 'Control SlowSequence Execution Frequency
end If
Loop 'end do while true
EndSequence


phishguy Nov 26, 2012 08:59 PM

Nevermind. I had OS version 24. I updated to version 25 and all is well.

Log in or register to post/reply in the forum.