S Smee Well-Known Member Licensed User Longtime User May 2, 2012 #1 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 Code: 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?
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 Code: 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?
Erel B4X founder Staff member Licensed User Longtime User May 2, 2012 #2 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: Code: LocalFileStamp = File.LastModified(...) Upvote 0
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: Code: LocalFileStamp = File.LastModified(...)
S Smee Well-Known Member Licensed User Longtime User May 2, 2012 #3 Erel said: 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: Code: LocalFileStamp = File.LastModified(...) Click to expand... Guess i am still learning, Many thanks Erel Upvote 0
Erel said: 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: Code: LocalFileStamp = File.LastModified(...) Click to expand... Guess i am still learning, Many thanks Erel
S Smee Well-Known Member Licensed User Longtime User May 2, 2012 #4 I tried that code but it still does not work. This is what i have Code: 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
I tried that code but it still does not work. This is what i have Code: 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
Erel B4X founder Staff member Licensed User Longtime User May 2, 2012 #5 You should also update the second line in the same manner as the first one. Calling DateTime.DateParse removes the hours and minutes from the date (and is completely unnecessary in this case). Upvote 0
You should also update the second line in the same manner as the first one. Calling DateTime.DateParse removes the hours and minutes from the date (and is completely unnecessary in this case).
S Smee Well-Known Member Licensed User Longtime User May 2, 2012 #6 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
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
Erel B4X founder Staff member Licensed User Longtime User May 2, 2012 #7 This is the correct syntax: Code: ServerFileStamp=Files(i).Timestamp Upvote 0
S Smee Well-Known Member Licensed User Longtime User May 2, 2012 #8 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
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
Erel B4X founder Staff member Licensed User Longtime User May 2, 2012 #9 Maybe the server uses a different timezone. You should add some log message with DateTime.Time(<ticks value>) and see the actual values returned. Upvote 0
Maybe the server uses a different timezone. You should add some log message with DateTime.Time(<ticks value>) and see the actual values returned.
S Smee Well-Known Member Licensed User Longtime User May 3, 2012 #10 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: May 3, 2012 Upvote 0
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
S Smee Well-Known Member Licensed User Longtime User May 3, 2012 #11 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: May 3, 2012 Upvote 0
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?
M Mahares Expert Licensed User Longtime User May 3, 2012 #12 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. Code: 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: Code: 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
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. Code: 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: Code: 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
ilan Expert Licensed User Longtime User Apr 13, 2013 #13 really great mahares you helped me a lot with your solution thanx !! Upvote 0
S Smee Well-Known Member Licensed User Longtime User Apr 14, 2013 #14 Thanks from me too. i must have missed this when you posted Upvote 0