sql - Military date/time to_char meridian indicator option -
running postgresql 7.4(yep we're upgrading)
field data type: timestamp time zone
format this: 2011-06-30 19:18:07-04
converting format:
to_char(datetime_field, 'mm-dd-yyyy hh12:mi:ss') "new date" output this:
06-30-2011 07:18:07 but need add meridian indicator.
desired results:
// if 06-30-2011 07:18:07 // if pm 06-30-2011 07:18:07 pm is there option can pass this?
so example datetime give
2011-06-30 19:18:07-04 should this:
06-30-2011 07:18:07 pm update:
well i'm still looking option pass workaround did:
case when date_part('hour', datetime_field) > 12 to_char(datetime_field, 'mm-dd-yyyy hh12:mi:ss pm') else to_char(datetime_field, 'mm-dd-yyyy hh12:mi:ss am') end "new date"
according documentation page (for v8.2), can use any pattern list: am, am, pm, pm, a.m., a.m., p.m., p.m.. pattern chosen define style of indicator in output, whether ante meridiem or post meridiem, entirely depend on timestamp value.
so don't need employ case @ all. use whatever of two:
to_char(datetime_field, 'mm-dd-yyyy hh12:mi:ss am') "new date"to_char(datetime_field, 'mm-dd-yyyy hh12:mi:ss pm') "new date"
was asking about?
Comments
Post a Comment