Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format time to hh:mm? and 24h?

Hi
I am trying to get time to format to only show hour and minutes (no
seconds). But this code does not work. How shall I do?
And how can I make it to show 24h in stead of AM/PM?
The Region Date and Time on my pc is changed to English(USA) to simplify it.

Thanks
Rolf

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As Date

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox (cTime)

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Format time to hh:mm? and 24h?

Try

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As String

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox cTime

End Sub

HTH

Bob

"Rolf Edberg" wrote in message
...
Hi
I am trying to get time to format to only show hour and minutes (no
seconds). But this code does not work. How shall I do?
And how can I make it to show 24h in stead of AM/PM?
The Region Date and Time on my pc is changed to English(USA) to simplify
it.

Thanks
Rolf

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As Date

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox (cTime)

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Format time to hh:mm? and 24h?

How about this:

Sub HoursAndMinutes()
Dim aTime As String

aTime = "10:31:42"
MsgBox Left(aTime, Len(aTime) - 3)

End Sub

All this does is chop the seconds and colon off the end of the initial
string, and doesn't require the additional variables or code steps.

HTH
Bill

"Rolf Edberg" wrote:

Hi
I am trying to get time to format to only show hour and minutes (no
seconds). But this code does not work. How shall I do?
And how can I make it to show 24h in stead of AM/PM?
The Region Date and Time on my pc is changed to English(USA) to simplify it.

Thanks
Rolf

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As Date

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox (cTime)

End Sub


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Format time to hh:mm? and 24h?

Thank you for your suggestion! I will show my bigger problem then it easier
to find the right solution( in the general list). Rolf
"Bob Phillips" schrieb im Newsbeitrag
...
Try

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As String

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox cTime

End Sub

HTH

Bob

"Rolf Edberg" wrote in message
...
Hi
I am trying to get time to format to only show hour and minutes (no
seconds). But this code does not work. How shall I do?
And how can I make it to show 24h in stead of AM/PM?
The Region Date and Time on my pc is changed to English(USA) to simplify
it.

Thanks
Rolf

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As Date

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox (cTime)

End Sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Format time to hh:mm? and 24h?

Thank you for your suggestion! I will show my bigger problem then it easier
to find the right solution( in the general list). Rolf
"fisch4bill" schrieb im Newsbeitrag
...
How about this:

Sub HoursAndMinutes()
Dim aTime As String

aTime = "10:31:42"
MsgBox Left(aTime, Len(aTime) - 3)

End Sub

All this does is chop the seconds and colon off the end of the initial
string, and doesn't require the additional variables or code steps.

HTH
Bill

"Rolf Edberg" wrote:

Hi
I am trying to get time to format to only show hour and minutes (no
seconds). But this code does not work. How shall I do?
And how can I make it to show 24h in stead of AM/PM?
The Region Date and Time on my pc is changed to English(USA) to simplify
it.

Thanks
Rolf

Sub HoursAndMinutes()
Dim aTime As String
Dim bTime As Date
Dim cTime As Date

aTime = "10:31:42"
bTime = CDate(aTime)
cTime = Format(bTime, "hh:mm")
MsgBox (cTime)

End Sub


.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 4 February 13th 09 04:34 PM
How to format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 1 February 13th 09 01:37 AM
How to format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 0 February 13th 09 12:49 AM
How to type format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 1 February 13th 09 12:09 AM
Remove time from a date and time field? Format removes the displa. oaoboc Excel Worksheet Functions 1 February 16th 05 07:20 PM


All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"