Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default VBA time conversion

Suppose I have the following string variable:

s = "10:20 PM"

Is there a function that will convert s to military like so?:

s = "2200" ' Now represents military time

-Robert



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA time conversion

"RG III" wrote in message
Suppose I have the following string variable:

s = "10:20 PM"

Is there a function that will convert s to military like so?:

s = "2200" ' Now represents military time

-Robert


There's no builtin function but easy enough to roll your own. But why not
simply number-format the cell(s) with "hhmm"

Peter T


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default VBA time conversion

On Wednesday, September 25, 2019 at 8:31:31 AM UTC-7, Peter T wrote:

There's no builtin function but easy enough to roll your own. But why not
simply number-format the cell(s) with "hhmm


The data is not stored in a cell. I was just trying to find a method to convert time strings stored in variables.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default VBA time conversion

Hi,

Am Wed, 25 Sep 2019 11:06:07 -0700 (PDT) schrieb RG III:

The data is not stored in a cell. I was just trying to find a method to convert time strings stored in variables.


try:

s = "10:20 PM"
t = TimeValue(s)
s = Hour(t) & Minute(t)


Regards
Claus B.
--
Windows10
Office 2016
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default VBA time conversion

On Wednesday, September 25, 2019 at 11:20:51 AM UTC-7, Claus Busch wrote:

s = "10:20 PM"
t = TimeValue(s)
s = Hour(t) & Minute(t)


Those functions are a big help. The only problem is if the
input is something like this:

s = "10:04 PM" ' Output == "224"

I guess if the minutes value is less than 10, I just need to prefix
the minutes with a "0"


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default VBA time conversion

Hi,

Am Wed, 25 Sep 2019 11:37:31 -0700 (PDT) schrieb RG III:

The only problem is if the
input is something like this:

s = "10:04 PM" ' Output == "224"


then try:

s = "10:04 PM"
t = TimeValue(s)
s = Format(Hour(t), "00") & Format(Minute(t), "00")


Regards
Claus B.
--
Windows10
Office 2016
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
Time Conversion Jodi Macy[_2_] Excel Worksheet Functions 3 January 5th 09 08:33 PM
time conversion GAIDEN Excel Worksheet Functions 3 November 17th 08 03:00 AM
Time Conversion Richard Excel Discussion (Misc queries) 2 June 15th 07 04:04 PM
time conversion sup191 Excel Programming 13 June 17th 04 05:28 PM
TIME CONVERSION Tom Excel Programming 1 May 25th 04 12:33 PM


All times are GMT +1. The time now is 07:07 PM.

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

About Us

"It's about Microsoft Excel"