SetFileDate() and GetFileDate()

Just starting out? Need help? Post your questions and find answers here.
User_Russian
Addict
Addict
Posts: 1593
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

SetFileDate() and GetFileDate()

Post by User_Russian »

If you look at the file properties in Explorer, the time is an hour longer than specified.

Code: Select all

Date.q = Date(2010, 4, 8, 2, 0, 0)
File.s = GetTemporaryDirectory()+"Test.txt"
CreateFile(0, File)
CloseFile(0)
SetFileDate(File, #PB_Date_Created, Date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", Date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Created))
RunProgram(GetTemporaryDirectory())
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: SetFileDate() and GetFileDate()

Post by juergenkulow »

Code: Select all

; SetFileDate Linux 
File.s = GetTemporaryDirectory()+"Test.txt"
CreateFile(0, File)
CloseFile(0)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Created))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Modified))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Accessed))
date=Date(2024,2,13,14,15,16)
SetFileDate(File, #PB_Date_Modified, date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Created))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Modified))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Accessed))
SetFileDate(File, #PB_Date_Created, date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Created))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Modified))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Accessed))
SetFileDate(File, #PB_Date_Accessed, date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Created))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Modified))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", GetFileDate(File, #PB_Date_Accessed))

; 2024/02/12    23:14:50
; 2024/02/12    23:14:50
; 1970/01/01    00:00:00
; 2024/02/13    14:15:16
; 2024/02/13    14:15:16
; 1970/01/01    00:00:00
; 1970/01/01    00:00:00
; 1970/01/01    00:00:00
; 1970/01/01    00:00:00
; 1970/01/01    00:00:00
; 1970/01/01    00:00:00
; 1970/01/01    00:00:00
Lebostein
Addict
Addict
Posts: 840
Joined: Fri Jun 11, 2004 7:07 am

Re: SetFileDate() and GetFileDate()

Post by Lebostein »

same on mac OS

Code: Select all

2024/02/14    06:28:47
2024/02/14    06:28:47
1970/01/01    00:00:00
2024/02/13    14:15:16
2024/02/13    14:15:16
1970/01/01    00:00:00
1970/01/01    00:00:00
1970/01/01    00:00:00
1970/01/01    00:00:00
1970/01/01    00:00:00
1970/01/01    00:00:00
1970/01/01    00:00:00
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: SetFileDate() and GetFileDate()

Post by Fred »

When you use an absolute date, there is no timezone info in it. As you can see GetFileDate(File, #PB_Date_Created) returns 1270692000 which is the correct EPOCH time for Apr 08 02:00:00 2010. Explorer probably display the time using the current timezone, that's why it's different.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: SetFileDate() and GetFileDate()

Post by juergenkulow »

Linux:

Code: Select all

2024/03/02    17:50:14
2024/03/02    17:50:14
1970/01/01    00:00:00
2024/02/13    14:15:16 <----- reads #PB_Date_Modified not #PB_Date_Created
2024/02/13    14:15:16
1970/01/01    00:00:00
1970/01/01    00:00:00 <----- #PB_Date_Created missing
1970/01/01    00:00:00
1970/01/01    00:00:00
1970/01/01    00:00:00 <------ #PB_Date_Created missing
1970/01/01    00:00:00
1970/01/01    00:00:00 <------ #PB Date_Accessed not set 
After SetFileDate(File, #PB_Date_Modified, date) Date created and Date modified are different :
Image
After SetFileDate(File, #PB_Date_Created, date) :
Image
After SetFileDate(File, #PB_Date_Accessed, date) :
Image
Post Reply