SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 ASP.NET
 24 hour Time Format
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vk18
Posting Yak Master

146 Posts

Posted - 03/30/2007 :  17:59:01  Show Profile  Reply with Quote
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

USA
36845 Posts

Posted - 03/30/2007 :  18:26:31  Show Profile  Visit tkizer's Homepage  Reply with Quote
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 - 04/02/2007 :  14:22:11  Show Profile  Reply with Quote
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

Sweden
30217 Posts

Posted - 04/02/2007 :  14:53:41  Show Profile  Visit SwePeso's Homepage  Reply with Quote
FORMAT(Node, "yyyy-mm-dd")


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

vk18
Posting Yak Master

146 Posts

Posted - 04/02/2007 :  15:53:17  Show Profile  Reply with Quote
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

Sweden
30217 Posts

Posted - 04/03/2007 :  00:30:09  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

Costa Rica
1 Posts

Posted - 04/13/2007 :  14:22:31  Show Profile  Reply with Quote
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

USA
7423 Posts

Posted - 04/13/2007 :  15:02:53  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
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

India
22754 Posts

Posted - 04/14/2007 :  03:31:05  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
1 Posts

Posted - 09/15/2010 :  06:04:09  Show Profile  Reply with Quote
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

India
22754 Posts

Posted - 09/15/2010 :  10:08:23  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.23 seconds. Powered By: Snitz Forums 2000