| Author | Topic | 
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                        415 Posts | 
                                            
                                            |  Posted - 2009-03-06 : 15:28:53 
 |  
                                            | How to convert military time to standard time15:12:47 to 2:12:47 PM?9:13:33 to 9:13:33 AM? |  | 
       
                            
                       
                          
                            
                                    | lmnorms
 
 
                                    8 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:38:14 
 |  
                                          | Hello,Military time is also called 24 hour time. From 00:00:01 to 24:00:00. If the time is less than 12:00:00 just use clock time. But from 12:59:59 forward the time should take the clock time and add 12 hours. For 1:00 pm it would convert to 13:00 hrs. To get the time from 'Military' time subtract 12 hours.  14:12:47 is 2:12:47pm. Hope the information helps. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:40:47 
 |  
                                          | do u have any script i will test? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | lmnorms
 
 
                                    8 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:41:52 
 |  
                                          | Actually, I think I have a vb script has an example if that is ok. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:42:55 
 |  
                                          | let me try |  
                                          |  |  | 
                            
                       
                          
                            
                                    | lmnorms
 
 
                                    8 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:47:18 
 |  
                                          | Here are some functions. If you need something else let me know. ' convert to a string in military timeDim input As String = DateTime.Now.ToString(militaryTimeFormat)' convert from a string in military timeDim time As DateTime = DateTime.ParseExact(input,militaryTimeFormat, Nothing) |  
                                          |  |  | 
                            
                       
                          
                            
                                    | lmnorms
 
 
                                    8 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:47:47 
 |  
                                          | Here are some functions. If you need something else let me know. ' convert to a string in military timeDim input As String = DateTime.Now.ToString(militaryTimeFormat)' convert from a string in military timeDim time As DateTime = DateTime.ParseExact(input,militaryTimeFormat, Nothing) |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:50:44 
 |  
                                          | i don't think so its gonna implement on sql script?ParseExact is your own function?? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | lmnorms
 
 
                                    8 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 15:53:57 
 |  
                                          | No. These are vb functions. You should have access to similar sql functions that retrieve time. Tell me a little more about the situation. How, and why do you need to convert? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:07:01 
 |  
                                          | it does not implement on T-SQL.guys any body have idea? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | vijayisonlyMaster Smack Fu Yak Hacker
 
 
                                    1836 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:08:05 
 |  
                                          | IS it a datetime field that you are trying to convert? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:10:05 
 |  
                                          | yes its datetime field.i don't need date. Just need to convert time.Like this: 15:12:47 to 3:12:47 PM?9:13:33 to 9:13:33 AM? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:33:45 
 |  
                                          | vijayisonly, did u get? quote:Originally posted by vijayisonly
 IS it a datetime field that you are trying to convert?
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | vijayisonlyMaster Smack Fu Yak Hacker
 
 
                                    1836 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:36:28 
 |  
                                          | Try this...SELECT LTRIM(RIGHT(CONVERT(char,urcol,109),18)) from urtable |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:43:05 
 |  
                                          | thanks vijayisonly. good job |  
                                          |  |  | 
                            
                       
                          
                            
                                    | sakets_2000Master Smack Fu Yak Hacker
 
 
                                    1472 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:43:09 
 |  
                                          | 109 will return you milliseconds as well. Try this, select right(convert(varchar, getdate(),0),7) |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:52:30 
 |  
                                          | Yes its return milliseconds too. I don't need milliseconds. I tried this but get errSELECT LTRIM(RIGHT(CONVERT(char,mycol,09),7)) from mytbl |  
                                          |  |  | 
                            
                       
                          
                            
                                    | sakets_2000Master Smack Fu Yak Hacker
 
 
                                    1472 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 16:59:30 
 |  
                                          | [code]SELECT  right(convert(varchar, mycol,0),7) from mytbl[/code] |  
                                          |  |  | 
                            
                       
                          
                            
                                    | rudbaConstraint Violating Yak Guru
 
 
                                    415 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 17:13:28 
 |  
                                          | how to get seconds quote:Originally posted by sakets_2000
 
 SELECT  right(convert(varchar, mycol,0),7) from mytbl 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | vijayisonlyMaster Smack Fu Yak Hacker
 
 
                                    1836 Posts | 
                                        
                                          |  Posted - 2009-03-06 : 17:58:47 
 |  
                                          | Do this...SELECT REPLACE(LTRIM(RIGHT(CONVERT(char,urcol,109),18)),':000',' ') from urtable |  
                                          |  |  | 
                            
                            
                                |  |