ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   minutes & seconds functions (https://www.excelbanter.com/excel-programming/437372-minutes-seconds-functions.html)

Robert Crandal

minutes & seconds functions
 
Does VBA have any built in functions that test if a
string is properly formatted in minutes and seconds
notation such as: mm:ss???

For example, if the function is given a string value
of "1:22" or "0:22" or ":45", then the function should
return TRUE! However, the function would return
false if it was given strings such as: "6a:20" or "hello" etc...

thnx



Rob van Gelder

minutes & seconds functions
 
Use the IsDate function

However, you'll note that ":45" is not considered a valid date.

Sub test()
Debug.Print IsDate("1:22")
Debug.Print IsDate("0:22")
Debug.Print IsDate(":45")
Debug.Print IsDate("6a:20")
Debug.Print IsDate("hello")
End Sub

Cheers,
Rob


On 13-Dec-2009 14:39, Robert Crandal wrote:
Does VBA have any built in functions that test if a
string is properly formatted in minutes and seconds
notation such as: mm:ss???

For example, if the function is given a string value
of "1:22" or "0:22" or ":45", then the function should
return TRUE! However, the function would return
false if it was given strings such as: "6a:20" or "hello" etc...

thnx


Robert Crandal

minutes & seconds functions
 
Are there a family of functions related to "IsDate" which
extract minutes and seconds???

For example:

GetMinutes("22:42") == would return "22"
GetSeconds("13:01") == would return "01"


"Rob van Gelder" wrote in message
...
Use the IsDate function

However, you'll note that ":45" is not considered a valid date.

Sub test()
Debug.Print IsDate("1:22")
Debug.Print IsDate("0:22")
Debug.Print IsDate(":45")
Debug.Print IsDate("6a:20")
Debug.Print IsDate("hello")
End Sub

Cheers,
Rob



Rob van Gelder

minutes & seconds functions
 
Sub test()
Debug.Print Minute("00:22:42")
Debug.Print Second("00:13:01")
End Sub

note that 22:42 would be interpreted as 10pm, not 22 minutes.



On 13-Dec-2009 16:54, Robert Crandal wrote:
Are there a family of functions related to "IsDate" which
extract minutes and seconds???

For example:

GetMinutes("22:42") == would return "22"
GetSeconds("13:01") == would return "01"


"Rob van Gelder" wrote in message
...
Use the IsDate function

However, you'll note that ":45" is not considered a valid date.

Sub test()
Debug.Print IsDate("1:22")
Debug.Print IsDate("0:22")
Debug.Print IsDate(":45")
Debug.Print IsDate("6a:20")
Debug.Print IsDate("hello")
End Sub

Cheers,
Rob




All times are GMT +1. The time now is 11:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com