Results 1 to 10 of 10

Thread: format times

  1. #1
    Join Date
    Aug 2003
    Posts
    64

    Unanswered: format times

    easy answer to my question?

    using the DatePart function, works fine for minutes.
    MinElasped: DatePart("h",[Elasped])*60+DatePart("n",[Elasped])

    but having problems trying to display hours.
    HrsElasped: DatePart("h",[Elasped])+DatePart("n",[Elasped])/60,
    my results are; 0.133333333333333. I prefer exp. 3.5 hrs..

    Please include a way to manipulate times rolling over midnight to prevent negative numbers.

  2. #2
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    do this:

    HrsElasped: DatePart("h",[Elasped])+(DatePart("n",[Elasped]))/60
    Saludos
    Norberto

  3. #3
    Join Date
    Aug 2003
    Posts
    64

    format times

    Sorry, your suggestion did not work but I tried somthing esle.


    Tried the DateDiff function, works ok but getting negative numbers when rolling over midnight. Please help...


    MinElasped: DateDiff("n",[start],[end])

    HrsElasped: DateDiff("h",[start],[end])

  4. #4
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    Why don't work what happen.
    Saludos
    Norberto

  5. #5
    Join Date
    Aug 2003
    Posts
    64
    your suggestion of,

    HrsElasped: DatePart("h",[Elasped])+(DatePart("n",[Elasped]))/60 did not work from your advice.
    My results are, 8.56666666666667 shoul be 8 or 8:34 hrs. Was able to use "DateDff" had a problem with sum over midnight.


    please advise

  6. #6
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    I sorry i thing you want that.
    If you want hour and minut why don't do that:
    HrsElasped: DatePart("h",[Elasped]) & ":" & DatePart("n",[Elasped])
    Saludos
    Norberto

  7. #7
    Join Date
    Aug 2003
    Posts
    64
    Your right, when I tried hour and minute unable to sum properly using a report.

    Your last example works, still unable to sum in a report or by month.
    The example below using minutes work properly but I like to use the same example below to properly sum hours using a report.

    Is there a way to convert the example to show minutes using this type of expression. Still being able to manipulate over midnight hours?

    MinElasped: DatePart("h",[Elasped])*60+DatePart("n",[Elasped])

  8. #8
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    Put a small sample of the Elasped field and i see what do
    Saludos
    Norberto

  9. #9
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    For the second problem this idea can work toub pp()
    Dim MinElasped
    Dim MyHours As Variant
    Dim MyMinutos As Variant
    Dim respuesta As String
    Dim posMinutos As Variant
    Dim respuesta1 As Variant
    Dim Numero As Variant

    MinElasped = DatePart("h", #1/1/03 10:00:00 AM#) + (DatePart("n", #1/1/03 10:30:00 AM#)) / 60
    respuesta = MinElasped
    posMinutos = InStr(1, respuesta, ",", vbBinaryCompare)
    MyHours = Val(Mid(respuesta, 1, (posMinutos - 1)))
    respuesta1 = Mid(respuesta, (posMinutos + 1))
    MyMinutos = Val(respuesta1) * 60 / 10

    End Sub
    Saludos
    Norberto

  10. #10
    Join Date
    Nov 2003
    Location
    Riga, Latvia
    Posts
    36
    Originally posted by comf36
    Your right, when I tried hour and minute unable to sum properly using a report.
    If that's the only problem, why can't you just use two fields - one for minutes, second for hours, and then sum them separately? Or, store the value in the db table as Norberto has suggested (i.e. 8.55 hrs) and anywhere you have to output it to user use a function to convert it into hours and minutes?
    Replies based on my configuration: Windows XP / Microsoft Office Access 2003 unless specified otherwise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •