Dgraph date.Time and golang time.Time

Hello.
What correct type I can add to dgraph dateTime type?
In golang

type Time1 struct {	
	TimeRFC       string    `json:"timerfc,omitempty"`
	TimeTimeRFC   time.Time `json:"ttrfc,omitempty"`
}

        ex := "02 Jan 2006"
        t, _ = time.Parse(ex, "11 Feb 2018")
	fmt.Println(t)
	trfc := t.Format(time.RFC3339)
	fmt.Println(trfc)
	fmt.Printf("%T\n", trfc)                                //string
	t2, _ := time.Parse(time.RFC3339, trfc)
	fmt.Println(t2)
	fmt.Printf("%T\n", t2)                                 //time.Time

schema:

                timerfc: dateTime .
		ttrfc: dateTime .

If I added string type trfc (golang) with timerfc: dateTime . it’s correct
And if I added date.Time type t2 (golang) with ttrfc: dateTime . It’s correct too.
What golang type is better to add?

Either works and depends on your use case. If you simply need to display the time, you can use string. If you need to do some datetime operations, use time.Time.

1 Like