ftp.date time question

Smee

Well-Known Member
Licensed User
Longtime User
I have an app that checks for a new file on the internet. If the internet version is newer then the download takes place if not it is left. My problem is that i seem to be ab le to only check the files date not the time. So if i download a new file in the morning then i am unable to download a newer file that is placed ther in the afternoon because the timestamps seem to be the same.

This is the code I am using

B4X:
   LocalFileStamp = DateTime.DateParse(DateTime.Date(File.LastModified(DeviceFolder & DeviceDirectory, ServerFileName)))
   ServerFileStamp=DateTime.DateParse(DateTime.Date(Files(i).Timestamp))

If (LocalFileStamp<ServerFileStamp) Then
          .....download
End If


Any suggestions?
 

Smee

Well-Known Member
Licensed User
Longtime User
You are first converting the ticks value to a string and then parse the string with DateParse (which only takes the date part). Why?

It should be:
B4X:
LocalFileStamp = File.LastModified(...)

Guess i am still learning,

Many thanks Erel
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
I tried that code but it still does not work. This is what i have

B4X:
   LocalFileStamp = File.LastModified(DeviceFolder & DeviceDirectory, ServerFileName)
   ServerFileStamp=DateTime.DateParse(DateTime.Date(Files(i).Timestamp))
   Log (LocalFileStamp)
   Log (ServerFileStamp)
   Log(ServerFileStamp-LocalFileStamp)

The log shows
1335945584000
1335880800000
-64784000

However there server file is newer by at least 5 hours not the other way round
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Erel,

I have tried the following all without success
:BangHead:

ServerFileStamp=Files(i).Timestamp
ServerFileStamp=DateTime.Date(Files(i).Timestamp)

what is the correct syntax for time and date of the file on the server.

Thanks
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
When i tried that syntax i got the following results

1335945584000
1335904980000
-40604000

Therefore the file does not download because of the line

If LocalFileStamp<ServerFileStamp then
download
end if

Because the figures are showing the file on the server has an earlier date then the one downlaoded but this is not correct
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
That would be it. I am in Australia and the server is located in the USA. How would I be able to compensate for the time difference?

Update
The server is on MST which is UTC -7 or -16 hours i think. I am on GMT+10
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Thanks for the feedback Erel,

the logs i put in were
Log(DateTime.Time(LocalFileStamp))
log(DateTime.Time(ServerFileStamp))

this gives me
09:23:28
03:30:00

so it just shows the time diff of the file. What i am trying to achive is to check if the file on the server against the file on the device so i need the time AND the date because there may be multiple uploads during the day,

Could you advise the correct code?


Thanks again


UPDATE:

if i use the following code it seems to work ok.
ServerFileStamp=Files(i).Timestamp + (3600000*17)
is this a legit solution that would work in all cases? How would i adjust for daylight saving time from MST to MDT?
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
How about this: If the server time 9:14:17, the local time is 6 hours later. You can even set the minutes and seconds. You could also work it the other way. If you know the local time and want to calculate the server time use -6 for the hours.

B4X:
Dim ServerFileStamp,LocalFileStamp As Long
Dim LocalTime As String
ServerFileStamp=DateTime.Now
LocalFileStamp= TimeAdd(ServerFileStamp,6,0,0)   '6 hours later
LocalTime=DateTime.Time(LocalFileStamp)
Msgbox(LocalTime,"")
which uses the below sub:
B4X:
Sub TimeAdd(Ticks As Long, Hours As Int, Minutes As Int, Seconds As Int) As Long
    Return Ticks + Hours * DateTime.TicksPerHour + Minutes * DateTime.TicksPerMinute + Seconds * DateTime.TicksPerSecond
End Sub
 
Upvote 0
Top