Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 24 hour Time Format

Author  Topic 

vk18
Posting Yak Master

146 Posts

Posted - 2007-03-30 : 17:59:01
Hi,

I have a 12hour Format time in one of the Sql Server Table. I want to convert into 24 hour format. Can you guys help me with this. I am using VB.NET/ASP.NET and SqlServer 2000.
I have like 08:20:00pm . what i want is 20:20:00
Appreciate your help
Thx

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-03-30 : 18:26:31
Isn't there a DateFormat function in VB.NET?

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

vk18
Posting Yak Master

146 Posts

Posted - 2007-04-02 : 14:22:11
quote:
Originally posted by vk18

Hi,

I have a 12hour Format time in one of the Sql Server Table. I want to convert into 24 hour format. Can you guys help me with this. I am using VB.NET/ASP.NET and SqlServer 2000.
I have like 08:20:00pm . what i want is 20:20:00
Appreciate your help
Thx


Hi,
I tried the following function for converting 12 hour time format to 24 Hour time format. but when i run this function in vb.net no time is showing, can you guys help me what i am doing wrong.? Appreciate your help.
Thx

Public Function SetDateTime(ByVal myNode As String) As String
Dim NOONORMIDNIGHT As Integer = 12
Dim myDate As String = myNode.Substring(0, 10)
Dim myTime As String = myNode.Substring(11, 8)

If Not (myNode Is Nothing) Then
Dim ifbefore10am As String = ""
Dim remainderoftimestringafterhour As Integer = 0
'not sure of how to get military time, so I'll add 12 hours, unless the time is 12, then I'll subtract 12
Dim ihr As Integer
If [String].Compare(myTime.Substring(2, 1), ":") = 0 Then
remainderoftimestringafterhour = 2
ihr = Convert.ToInt32(myTime.Substring(0, remainderoftimestringafterhour))
Else
remainderoftimestringafterhour = 1
ihr = Convert.ToInt32(myTime.Substring(0, remainderoftimestringafterhour))
End If

If [String].Compare(myTime.Substring(myTime.Length - 2, 2), "PM") = 0 Then
If [String].Compare(myTime.Substring(0, 2), Convert.ToString(NOONORMIDNIGHT)) <> 0 Then
ihr += NOONORMIDNIGHT
End If
Else
If [String].Compare(myTime.Substring(0, 2), Convert.ToString(NOONORMIDNIGHT)) = 0 Then
'do something - MIDNIGHT
ihr = 0
ifbefore10am = "0"
Else
'not MIDNIGHT, but before 10:00:00 AM
If ihr < 10 Then
ifbefore10am = "0"
End If
End If
End If
myNode = myDate + "T" + ifbefore10am + Convert.ToString(ihr) + myTime.Substring(remainderoftimestringafterhour, 6)
End If
End Function
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-02 : 14:53:41
FORMAT(Node, "yyyy-mm-dd")


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

vk18
Posting Yak Master

146 Posts

Posted - 2007-04-02 : 15:53:17
quote:
Originally posted by Peso

FORMAT(Node, "yyyy-mm-dd")


Peter Larsson
Helsingborg, Sweden


Hi Peso,
you want me to include FORMAT(Node, "yyyy-mm-dd") in my function..?
thx
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-03 : 00:30:09
Yes. In this and all other FORMAT questions you have posted.
Just change the format option to a reasonable string for the function in question.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

kquiros
Starting Member

1 Post

Posted - 2007-04-13 : 14:22:31
Hi... sorry for my english... i'm learn...

you only need to put this code in your query or select::::

"select convert(varchar(12),cast('08:20:00pm ' as datetime),8)"

jeje... cool!!!

Kenneth Quiros Chaves
Pentáculo Software
Alajuela, Costa Rica
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-04-13 : 15:02:53
quote:
Originally posted by kquiros

Hi... sorry for my english... i'm learn...

you only need to put this code in your query or select::::

"select convert(varchar(12),cast('08:20:00pm ' as datetime),8)"

jeje... cool!!!

Kenneth Quiros Chaves
Pentáculo Software
Alajuela, Costa Rica



No, you don't. That returns a VARCHAR from the database, not a DateTime. Formatting should always be done at the front-end unless you have no other option.


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-14 : 03:31:05
quote:
Originally posted by kquiros

Hi... sorry for my english... i'm learn...

you only need to put this code in your query or select::::

"select convert(varchar(12),cast('08:20:00pm ' as datetime),8)"

jeje... cool!!!

Kenneth Quiros Chaves
Pentáculo Software
Alajuela, Costa Rica


you only need to format it in ASP.NET

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harshul
Starting Member

1 Post

Posted - 2010-09-15 : 06:04:09
quote:
Originally posted by Peso

This is a perfect solution to convert time into 24 hours format from sql it self!
I think it is good to convert the format if it is mandetory for the client end to use at the back end it self as I believe it is more efficient.

Harshul Shah
CrossShore Solutions, India

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-15 : 10:08:23
quote:
Originally posted by harshul

quote:
Originally posted by Peso

This is a perfect solution to convert time into 24 hours format from sql it self!
I think it is good to convert the format if it is mandetory for the client end to use at the back end it self as I believe it is more efficient.

Harshul Shah
CrossShore Solutions, India




Have you read previous two replies?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -