Dgraph date.Time and golang time.Time

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")
	trfc := t.Format(time.RFC3339)
	fmt.Printf("%T\n", trfc)                                //string
	t2, _ := time.Parse(time.RFC3339, trfc)
	fmt.Printf("%T\n", t2)                                 //time.Time


                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