find the creation date of a csv file in go

To find the creation date of a csv file in Go, one can use the os.Stat function from the os package.

main.go
package main

import (
    "fmt"
    "os"
)

func main() {
    filename := "data.csv"
    fileinfo, err := os.Stat(filename)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println("File created on:", fileinfo.ModTime())
}
234 chars
16 lines

Here, we import the os package and use the os.Stat function to get information about the file. When successful, we print the last modification time of the file. This is because the creation time of a file is not stored in a standard way across all file systems. Instead, we can get the last modification time, which should indicate when the file was created if it has not been modified since then.

Make sure to substitute data.csv with the name of your csv file.

gistlibby LogSnag