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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -