Desired format to write time stamp, in cassandra database:
2021-01-17 21:51:46.195
Using cqlsh syntax for insert query:
am able to write the above format using
toTimeStamp(toDate(now()))
Using cqlsh, am unable to write the above format using
toUnixTimestamp(now())
.toUnixTimestamp(now())
writes the format2021-01-17 21:51:46.195000+0000
.
layout := "2006-01-02T15:04:05.000Z"
timestamp := "2021-01-17T21:51:46.195Z"
createdDate, err := time.Parse(layout, timestamp)
insertQueryString = "INSERT INTO mytable(created_date) " + "VALUES (?)"
gocql.Session.Query(insertQueryString, createdDate).Exec()
code also writes createdDate
into database similar to the format that cqlsh's toUnixTimestamp(now())
does, which is 2021-01-17 21:51:46.195000+0000
as shown below:
JimB already explained: "Again, time.Time has no format. You can format it as a string if you want, which is explained in numerous other answers."
But,
How to make gocql.Session.Query(insertQueryString, createdDate).Exec()
write createdDate
as 2021-01-17 21:51:46.195
? Because cqlsh
is able to write this desired format using toTimeStamp(toDate(now()))