Original post

I (as an unexperienced programmer) wrote a program (“stolen” from the web) that reads generic database tables and exports this data to a csv file. The program scans database record into a bytes slice then simply assigns a string slice using the string(raw) code.

In case of datetime database field the resulting string value is the default “2006-01-02T15:04:05-0700” go format, so the question is how can i change the resulting format?

Thanks in advance,

What outut do you want instead? Note that what you have is ISO 8601, a very common and portable format for dates and datetimes.

Use Time.Format:

package main

import (

func main() {
        t, _ := time.Parse(time.UnixDate, "Sat Mar  7 11:06:39 PST 2015")
        s := t.Format("02.01.2006, 15:04:05")


2015-03-07 11:06:39 +0000 PST
07.03.2015, 11:06:39