Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Proper Way To Determine AM or PM

Proper Way To Determine AM or PM

Scheduled Pinned Locked Moved C#
questionjson
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    perlmunger
    wrote on last edited by
    #1

    Until now, I've just gone on my merry way assuming that the only way to determine whether a time was AM or PM was either to get back a string with .ToShortDateString() and parse it out using Split, or to check to see if the Hours field in the date's TimeOfDay field was greater than 12. I haven't been happy with either answer, but haven't found a better one. What is the "proper" API way of doing this? Or is what I've mentioned all I get? -Matt ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

    H 1 Reply Last reply
    0
    • P perlmunger

      Until now, I've just gone on my merry way assuming that the only way to determine whether a time was AM or PM was either to get back a string with .ToShortDateString() and parse it out using Split, or to check to see if the Hours field in the date's TimeOfDay field was greater than 12. I haven't been happy with either answer, but haven't found a better one. What is the "proper" API way of doing this? Or is what I've mentioned all I get? -Matt ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Why not just check if DateTime.Hour >= 12?

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      P 1 Reply Last reply
      0
      • H Heath Stewart

        Why not just check if DateTime.Hour >= 12?

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        P Offline
        P Offline
        perlmunger
        wrote on last edited by
        #3

        I'm an idiot! I recall stepping through the debugger on a recent project and I could have sworn a 1 o'clock appointment record was coming up with an hour value of 1 rather than 13, but sure enough, I just built a simple desktop app to test it again and it came up with 13 on a 1:00 pm. I had just ASSumed that there was someething I was missing to determine meridian. Oh well. Here's to assuming!! Thanks. I appreciate you answering a stupid question. ;-) -Matt ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups