What’s the equivalent of sortable datetime/timestamp varchar in PostgreSQL?
Console.WriteLine("{0:s}", DateTime.Now);
sample format output:
2000-05-04T15:30:59
This works, SELECT now::varchar, output is ‘2009-03-25’, but only for date type, wondering what’s the equivalent for timestamp.
Note, i know date is sortable in and of itself, I just encounter a DateTime incompatibility between .NET and Mono, so i’ll just transport(Remoting) date/timestamp types as varchar, underlying database type is still proper date/timestamp field type. For those who encounter this same problem, the work-around is to cast the date to varchar when retrieving the data, and casting the varchar back to date when saving.
Basically you just use to_char function.
The problem with your example, is that while theoretically this should work:
In reality – PostgreSQL cannot “understand” that T is separator and HH24 is next “tag”, and prints it as:
But you can change it relatively simply to:
which outputs requested format:
Of course remembering always to use translate gets old pretty fast, so instead you can create your own function and use it instead: