Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Check that PM Time is greater than Am Time

For Example

A> 11:30 AM
B> 05:00 PM

i need that 5 PM is Greater than 11:30 Am because new updated time is 5 PM

Please Help Me.
Posted
Comments
Ankur\m/ 19-Mar-14 8:01am    
Isn't PM time always going to be greater than AM time. The day starts with 00:00 AM and after 12 hours the PM time starts.

What the point? PM is ALWAYS greater than AM!!! This kind of check has no meaning without the date part. More. The AM/PM is only a presentation format the time (or date-time) is really stored in binary (like milliseconds since the 01/01/1900), comparing two DateTime variable using VB will give you the exact answer without thinking even about if we are before or after midday...
 
Share this answer
 
 
Share this answer
 
Comments
hareshdgr8 19-Mar-14 8:22am    
Thank You Sir
you can check it out this code, it might help you...


VB
Dim stringAM As String = "11:30 AM"
       Dim stringPM As String = "05:00 PM"

       Dim dtAM As DateTime = DateTime.Parse(stringAM)
       Dim dtPM As DateTime = DateTime.Parse(stringPM)

       If dtPM > dtAM Then
           Console.WriteLine("PM is Greter Than AM")
       Else
           Console.WriteLine("PM is Less Than AM")
       End If

       'but if you have time along with date then you can try something like this..

       Dim stringDTAM As String = "19-March-2014 11:30 AM"
       Dim stringDTPM As String = "18-March-2014 05:00 PM"

       dtAM = DateTime.Parse(stringDTAM)
       dtPM = DateTime.Parse(stringDTPM)

       If dtPM > dtAM Then
           Console.WriteLine("PM is Greter Than AM")
       Else
           Console.WriteLine("PM is Less Than AM")
       End If


NOTE: if you are trying to check same day time for AM and PM then PM is always greater than AM, but if you are trying to check that with different dates then you might get AM is greater than PM, as shown in above example, in the second part, i have mention PM date is less then AM date, in that case it will return AM is greater then PM
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900