This topic is locked

time

2/15/2007 8:13:50 AM
ASPRunnerPro General questions
I
igiacchi author

In my report application I need to add 4 time values. I am a consultant and I go to the customer to give my support for servers and clients. At the and of my work I write an activities report. For examples: I start the work at 9:00 in the morning and I live for luch about 12:30, then I come back 14:30 and I stop my work 19:00. I have 4 fields R_ORASTART1, R_ORAEND1, R_ORASTART2, R_ORAEND2. I need to write the working time in one field R_ORETOTAL at the and of report. The formula is R_ORETOTAL = (R_ORAEND1 - R_ORASTART1) + (R_ORAEND2 - R_ORASTART2).

I have tried to resolve this problem but without result, could you help my about.

Many thanks in advance for your support.

Ivano

J
Jane 2/15/2007

Ivano,
you can do it using Before record updated event on the Events tab.

Event code will be dependent on type of your database.

I
igiacchi author 2/15/2007

Ivano,

you can do it using Before record updated event on the Events tab.

Event code will be dependent on type of your database.


Hi Jane,

I have just tried to put some code into "Before record updated" area like: Dict("R_ORETOTAL") = Dict("R_ORAEND") - Dict("R_ORASTART")... , but my without any result, I have tried to have any field response using: Response.Write Dict("R_ORETOTAL") and Session("R_ORETOTAL") no way !

My know how using ASP and ASPRunner is very poor, could you help me with the correct code.

Many thanks in advance.

Ivano

C
clig 2/15/2007



Здраствуйте Jane, не могли бы Вы помочь моему итальянскому другу - ответ, который Вы прислали недостаточно подробный.

Помогите пажалуйста тупым итальянцам.Если можете - на английском пожалуйста.
Yuri Trovati
Ivano Giacchi


This adds two datestamps together in number of hours including minutes - for example: StartTime= 02/14/2007 8:41:25 PM, EndTime= 02/14/2007 11:40:18 PM, TotalHours = 2.98
dict("TotalHours") = CAST(DATEDIFF(n, dict("StartTime"), dict("EndTime")) / 60 AS decimal(10, 4)) + CAST(CAST(DATEDIFF(n, dict("StartTime"), dict("EndTime")) - DATEDIFF(n, dict("StartTime"), dict("EndTime")) / 60 * 60 AS decimal(10, 4)) / 60 AS decimal(10, 4))

I
igiacchi author 2/16/2007



This adds two datestamps together in number of hours including minutes - for example: StartTime= 02/14/2007 8:41:25 PM, EndTime= 02/14/2007 11:40:18 PM, TotalHours = 2.98
dict("TotalHours") = CAST(DATEDIFF(n, dict("StartTime"), dict("EndTime")) / 60 AS decimal(10, 4)) + CAST(CAST(DATEDIFF(n, dict("StartTime"), dict("EndTime")) - DATEDIFF(n, dict("StartTime"), dict("EndTime")) / 60 * 60 AS decimal(10, 4)) / 60 AS decimal(10, 4))


Hi Sirs,

many thanks for your patient and your courtesy, I have tried to use your code but without any solution. I have receive this error from application:

Tipo di errore:
Errore di compilazione di Microsoft VBScript (0x800A03EE)

Previsto ')'

/Personale/include/Rapporti_events.asp, line 12, column 84

dict("R_TOTALEORA") = CAST(DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) / 60 AS decimal(10, 4)) + CAST(CAST(DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) - DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) / 60 * 60 AS decimal(10, 4)) / 60 AS decimal(10, 4))

-----------------------------------------------------------------------------------^
I have controlled the parentheses and they are exact I have tried also to use only a small part of the code like ( response.write DATEDIFF ( n, dict("R_ORASTART1"), dict("R_ORAEND1")) but he does not work.
Sigh !

I think that a good trip to Lourdes could be a good solution.
It is better that I will continue to work with firewall and server ...

Does not exist the solution for my problem?
Many thanks again
Ivano

C
clig 2/17/2007



Hi Sirs,

many thanks for your patient and your courtesy, I have tried to use your code but without any solution. I have receive this error from application:

Tipo di errore:
Errore di compilazione di Microsoft VBScript (0x800A03EE)

Previsto ')'

/Personale/include/Rapporti_events.asp, line 12, column 84

dict("R_TOTALEORA") = CAST(DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) / 60 AS decimal(10, 4)) + CAST(CAST(DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) - DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) / 60 * 60 AS decimal(10, 4)) / 60 AS decimal(10, 4))

-----------------------------------------------------------------------------------^
I have controlled the parentheses and they are exact I have tried also to use only a small part of the code like ( response.write DATEDIFF ( n, dict("R_ORASTART1"), dict("R_ORAEND1")) but he does not work.
Sigh !

I think that a good trip to Lourdes could be a good solution.
It is better that I will continue to work with firewall and server ...

Does not exist the solution for my problem?
Many thanks again
Ivano


A sample using this type of thing in a query:
SELECT ID, Login, Project, StartTime, EndTime, DATEDIFF(n, StartTime, EndTime) / 60 AS Hours, DATEDIFF(n, StartTime, EndTime) - DATEDIFF(n, StartTime,

EndTime) / 60 * 60 AS Minutes, CAST(DATEDIFF(n, StartTime, EndTime) / 60 AS decimal(10, 4)) + CAST(CAST(DATEDIFF(n, StartTime, EndTime)

  • DATEDIFF(n, StartTime, EndTime) / 60 * 60 AS decimal(10, 4)) / 60 AS decimal(10, 4)) AS Total, Notes

    FROM dbo.JoesTime
  • The virtual column [Total] displays the total hours and minutes between StartTime and EndTime
  • So to write something like this somewhere with an asprunner event you'd need to take the code for [Hours] and [Minutes] and add them together just as they are done here to display a 3rd column of type decimal
  • The concept that 3 hours and 15 minutes does not equal 3.15 hours - but rather 3.25 hours total...
  • You could use the value of virtual column and update your underlying table...
  • I'm sure there is something simpler but I know this works in SQL... Maybe someone else can drop a comment or two on the thread...
  • http://www.w3schools.com/vbscript/func_datediff.asp
  • You will have to "CAST" for VBScript instead of using SQL CAST - http://support.technetex.ca/devguide/vbscript_functions.aspx
  • You could do this in pure VBScript without all the DATEDIFFs but then you'd have to account for "midnight"...
    ***

    Typecasting Functions
    Typecasting allows you to convert between data subtypes.
    Cint(expression) casts expression to an integer. If expression is a floating-point value or a currency value, it is rounded. If it is a string that looks like a number, it is turned into that number and then rounded if necessary. If it is a Boolean value of True, it becomes a -1. False becomes 0. It must also be within the range that an integer can store.
    Cbyte(expression) casts expression to a byte value provided that expression falls between 0 and 255. expression should be numeric or something that can be cast to a number.
    Cdbl(expression) casts expression to a double. expression should be numeric or something that can be cast to a number.
    Csng(expression) casts expression to a single. It works like Cdbl(), but must fall within the range represented by a single.
    Cbool(expression) casts expression to a Boolean value. If expression is 0, the result is False. Otherwise, the result is True. expression should be numeric or something that can be cast to a number.
    Ccur(expression) casts expression to a currency value. expression should be numeric or something that can be cast to a number.
    Cdate(expression) casts expression to a date value. expression should be numeric or something that can be cast to a number, or a string of a commonly used date format.

    DateValue(expression) or TimeValue(expression) can also be used for this.
    Cstr(expression) casts expression to a string. expression can be any kind of data.
    ****

    A VBA sample - can be converted to VBScript
    http://office.microsoft.com/en-us/assistan...1102181033.aspx
    Public Function ElapsedTimeString(dateTimeStart As Date, dateTimeEnd As Date) As String

    '****

    **

    ' Function ElapsedTimeString(dateTimeStart As Date, dateTimeEnd As Date) As String

    ' Returns the time elapsed between a starting Date/Time and an ending

    ' Date/Time formatted as a string that looks like this:

    ' "10 days, 20 hours, 30 minutes, 40 seconds".

    '****

    **
    Dim interval As Double, str As String, days As Variant

    Dim HOURS As String, MINUTES As String, SECONDS As String
    If IsNull(dateTimeStart) = True Or

    IsNull(dateTimeEnd) = True Then Exit Function
    interval = dateTimeEnd - dateTimeStart
    days = Fix(CSng(interval))

    HOURS = VBA.Format(interval, "h")

    MINUTES = VBA.Format(interval, "n")

    SECONDS = VBA.Format(interval, "s")
    ' Days part of the string

    str = IIf(days = 0, "",


    IIf(days = 1, days & " Day", days & " Days"))

    str = str & IIf(days = 0, "",

    IIf(HOURS & MINUTES & SECONDS <> "000", ", ", " "))
    ' Hours part of the string

    str = str & IIf(HOURS = "0", "",


    IIf(HOURS = "1", HOURS & " Hour", HOURS & " Hours"))

    str = str & IIf(HOURS = "0", "",

    IIf(MINUTES & SECONDS <> "00", ", ", " "))
    ' Minutes part of the string

    str = str & IIf(MINUTES = "0", "",


    IIf(MINUTES = "1", MINUTES & " Minute", MINUTES & " Minutes"))

    str = str & IIf(MINUTES = "0", "", IIf(SECONDS <> "0", ", ", " "))
    ' Seconds part of the string

    str = str & IIf(SECONDS = "0", "", _

    IIf(SECONDS = "1", SECONDS & " Second", SECONDS & " Seconds"))

    ElapsedTimeString = IIf(str = "", "0", str)
    End Function

C
clig 2/17/2007



Hi Sirs,

many thanks for your patient and your courtesy, I have tried to use your code but without any solution. I have receive this error from application:

Tipo di errore:
Errore di compilazione di Microsoft VBScript (0x800A03EE)

Previsto ')'

/Personale/include/Rapporti_events.asp, line 12, column 84

dict("R_TOTALEORA") = CAST(DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) / 60 AS decimal(10, 4)) + CAST(CAST(DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) - DATEDIFF(n, dict("R_ORASTART1"), dict("R_ORAEND1")) / 60 * 60 AS decimal(10, 4)) / 60 AS decimal(10, 4))

-----------------------------------------------------------------------------------^
I have controlled the parentheses and they are exact I have tried also to use only a small part of the code like ( response.write DATEDIFF ( n, dict("R_ORASTART1"), dict("R_ORAEND1")) but he does not work.
Sigh !

I think that a good trip to Lourdes could be a good solution.
It is better that I will continue to work with firewall and server ...

Does not exist the solution for my problem?
Many thanks again
Ivano


  • Assigning a Session Variable in BeforeEdit Event...
    Function BeforeEdit(dict, where)
    ' Parameters:

    ' dict - Scripting.Dictionary object.

    ' Each field on the Edit form represented as 'Field name'-'Field value' pair

    ' where - string with WHERE clause pointing to record to be edited
    '** Custom code ****

    ' put your custom code here
    intStart = Cdate(dict("StartTime"))

    intEnd = Cdate(dict("EndTime"))
    Session("intTotal") = FormatDateTime(intEnd - intStart, 4)
    BeforeEdit = True
    ' set BeforeEdit to True if you like to proceed with editing this record

    ' set it to False in other case
    End Function
    StartTime = 02/16/2007 20:14:16

    EndTime = 02/17/2007 02:50:19
    Session("intTotal") = 06:36
    *****
  • you could play with this string of 6 hours 36 minutes with MID etc...
    intTimeDiff = Session("intTotal")
    intFractional = (Cint(Mid(intTimeDiff,(instr(1,intTimeDiff,":")+1),len(intTimeDiff))) / 60)

    intHours = Left(intTimeDiff,2)
    Session("intTotal") = intHours & "." & Mid(intFractional,(instr(1,intFractional,".")+1),len(intFractional))
    Session("intTotal") = 06.6
  • I didn't test AM/PM/24...

I
igiacchi author 2/19/2007

Hi Clig,

many many thanks for your help I will try immediately your suggesting.

Thanks again
Ivano

I
igiacchi author 2/19/2007

Hi Clig,

I have solved using this code in the Add and Before Update.
intStart = Cdate(dict("R_ORASTART1"))

intEnd = Cdate(dict("R_ORAEND1"))
Ora1 = Cdate(FormatDateTime(intEnd - intStart, 4) + ".00")
intStart = Cdate(dict("R_ORASTART2"))

intEnd = Cdate(dict("R_ORAEND2"))
Ora2 = Cdate(FormatDateTime(intEnd - intStart, 4) + ".00")
Dict("R_TOTALEORA") = Cdate(FormatDateTime(Ora1 + Ora2, 4) + ".00")
Session("R_TOTALEORA") = Dict("R_TOTALEORA")
Many thanks again

Hi guys, this ASPRunner is truly big !