Time question

bubzuru

New member
Joined
Nov 13, 2007
Messages
1
Programming Experience
Beginner
How can i get whether its AM or PM in VB 2005

this works in VB6 but not in 2005 :(
VB.NET:
Format(Now, "AM/PM")
 
The hour component of a Date value is expressed as a value between 0 and 23. AM/PM is before/after 12 o'clock.
 
If you want a string to represent whether it's AM or PM then you do this:
VB.NET:
myString = Date.Now.ToString("tt")
...if you're in US or other country that has such designators (which OP most likely is), or explicitly formatting for such culture. Depending on the culture you get nothing or "AM" or "A/M" or other equivalent strings in return. Using the mathematical calculation on hour component is best if app is to be used by different cultures. For example comparing this formatted output to current cultures PM/AM-designators won't work when they both are empty strings.
 
Quite true. I wasn't suggesting using the string for comparison purposes. I only meant that if you wanted to represent to the user whether a time was AM or PM you would use that format.
 
Back
Top