+ Reply to Thread
Results 1 to 6 of 6

VBA help calculating UK and US date/times

  1. #1
    Registered User
    Join Date
    01-14-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    VBA help calculating UK and US date/times

    Hi guru's/geniuses/masterminds and helpers

    I have this quite good macro that looks at the data in 1 sheet and neatly collates the information with some calculation results in a 2nd sheet.

    The issue that I have is sheet 1 contains many dates in US format and when they are calculated doesn't return the correct result.

    I have narrowed it down to this. If the data returned from the macro is recognised as a US date, it works fine eg 15/1/15

    However if the data returned from the macro is not recognised as a US date, it doesnt work and returns a false or negative value eg 05/05/15

    I have tried so many things to change the lookup data but none of it makes any difference. I think it is something to do with the way the value's are calculated.

    Any help is appreciated.

    Evan
    Attached Files Attached Files

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: VBA help calculating UK and US date/times

    I haven't looked at you file but my first idea is why don't you convert all data and time entries to serial values
    DateSerial and TimeSerial, that way all values will be the same
    If you can't make it work, I'll check your file and see if I have another idea.
    The moment I open it, it will probably take into account that my system settings are Dutch so that would be an extra handicap
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    11-11-2015
    Location
    Southend
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA help calculating UK and US date/times

    Hi

    No need for VBA

    If your date is in cell b2 (as it is in your sheet) set another column =0+b2
    The zero will tell excel that you want a numeric value for the date and it will figure out the USA format
    All you then have to do is format the new cell as UK format (Home>Format>Format Cells>Custom and then "dd mmm yy" in the custom field which will display in UK format

    I have done so in column G of your spreadsheet as attached
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    01-14-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA help calculating UK and US date/times

    Thanks for trying Graham, I checked your example but it doesn't appear to have fixed the issue. I still receive negative values where they should be positive integers.

    I should point out that I did not write this code and I am no expert when it comes to VB.

    Steps taken - Remove blank column E. Changed column F to format "dd/mm/yy". Change Calendar A:A to same format.
    Update VB script for dtDate = oSheet.Cells(lngRowCount, 6)

    Output on Record Value tab still treats it as US format. I think it does this automatically when calculating regardless of the source formatting. refer to the first entry in K5 for IM1108554.
    Any value that spans greater than 1 day and contains a date that could be perceived to be in US format is affected. eg anything less than 12/12/15

    I appreciate you looking at this Graham, hopefully Keebellah is able to work out something with the DateSerial and TimeSerial codes.
    I need to be able to measure the time difference to the minute between the two dates so hopefully this works.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: VBA help calculating UK and US date/times

    I attached your file. I did not add any macros but just added several columns to the 'Information From SLA table' worksheet
    Columns G-K
    All I did is set the value of column B (update time) in G and changed the cell format to number and 5 decimals
    the header explains it.
    Now all the timestamps are long numbers and if you calculate based on these the time works (I think)
    Total time spent on Incident IM1086019 is 10 hours 46 minutes and 23 seconds, but I don't think that's correct since you have to take into account the days, but maybe it good, that you'll have to check yourself.

    This is just to show that if you use the timestamd (date and time) as serial number you don't have to worry about the date format.
    Hope this gives you some idea.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-14-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA help calculating UK and US date/times

    This issue has now been resolved by StephenCrump at MrExcel forum.

    The fixed comment is here:

    Ahh! Now I see your problem.

    Does it work if you change this line:

    If strPr > 2 Then intHolidays = Application.WorksheetFunction.CountIfs(Range("Dates"), ">=" & DateValue(dtSt), Range("dates"), "<=" & DateValue(dtEn), Range("working"), "N")

    to

    If strPr > 2 Then intHolidays = Application.WorksheetFunction.CountIfs(Range("Dates"), ">=" & CLng(dtSt), Range("dates"), "<=" & CLng(dtEn), Range("working"), "N")

    As a separate question, I haven't tried to follow what all your code is doing, so I'm not sure whether when you're doing this comparison you need to be working with integer dates (i.e. not including the time fraction)?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need to know how many times a unique date appears more than three times for each location
    By justaguyintx in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-15-2015, 03:04 PM
  2. Calculating Times
    By Lemarzo in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-14-2015, 01:16 AM
  3. calculating inter arrival times and statistical distribution of these times
    By ditmar.rijk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-19-2014, 03:18 AM
  4. Calculating a minutes duration based on start and end date and times
    By chrispx001 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-12-2013, 08:16 AM
  5. Macro Loop – Find Specific Times, Extract Date, Average Values of Times
    By ExcelQuestFL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-25-2010, 02:50 PM
  6. Replies: 1
    Last Post: 02-05-2009, 03:39 PM
  7. Macro to help sort date - times and average similar times.
    By ferretydeath in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2008, 05:44 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1