Remove Hours, Minutes, Seconds

gracm25

Registered User.
Local time
Yesterday, 18:04
Joined
Dec 6, 2007
Messages
31
In the below code, if time is less than 0, I would like for the entire phrase to read "EXPIRED". However, currently, it shows EXPIRED and then the number of hours minutes and seconds. I don't want it to show any hours minutes and seconds. Could someone help? Thanks!!

Public Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
'************************************************* ********************
' Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
' Returns the time elapsed between a fixed number and starting Date/Time and an ending
' Date/Time formatted as a string that looks like this:
' "10 days, 20 hours, 30 minutes".
'************************************************* ********************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String

If IsNull(TimeDays) = True Or _
IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function

interval = (TimeDays - (dateTimeEnd - dateTimeStart))

days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")

' Days part of the string
str = IIf(days < 0, "EXPIRED!", _
IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days")))
str = str & IIf(days = 0, "", _
IIf(hours & minutes <> "00", ", ", " "))
' Hours part of the string
str = str & IIf(hours < 0, "", _
IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours")))
str = str & IIf(hours = "0", "", _
IIf(minutes <> "0", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes < 0, "", _
IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", minutes & " Minutes")))
TimeRemaining = IIf(str = "", "0", str)

End Function
 
As you concatenate the time to the str you are bound to get that . Try
' Days part of the string

If days<0 then
str="EXPIRED"
Exit Function
End If

IIf(days = 0, "", _


Brian
 
Thanks for the suggestion. Now, the field that I want to read as "EXPIRED!" now is blank for that case only. Do you have any other suggestions? Thanks.


Public Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
'************************************************* ********************
' Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
' Returns the time elapsed between a fixed number and starting Date/Time and an ending
' Date/Time formatted as a string that looks like this:
' "10 days, 20 hours, 30 minutes".
'************************************************* ********************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String

If IsNull(TimeDays) = True Or _
IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function

interval = (TimeDays - (dateTimeEnd - dateTimeStart))

days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")

' Days part of the string
If days < 0 Then
str = "EXPIRED!!"
Exit Function
End If

str = IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days"))
str = str & IIf(days = 0, "", _
IIf(hours & minutes <> "00", ", ", " "))
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(minutes <> "0", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", minutes & " Minutes"))
TimeRemaining = IIf(str = "", "0", str)

End Function
 
silly me i forgot that Timeremaining has to be made = to str before exiting Function

Brian
 

Users who are viewing this thread

Back
Top Bottom