Results 1 to 12 of 12
  1. #1
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35

    Converting Short Text to Time

    Hi,

    I have some csv files that contain start times for events. Some records have no start time. I have pasted an extract below.

    Access 2016 imports them as short text so I am trying to convert to a time format. I already have a macro that converts dates from a separate field using CDate:

    Code:
    CurrentDb.Execute "UPDATE Matches SET Matches.ConvDate = CDate(Date)", dbFailOnError
    I'm not clear whether I can use CDate for this or if I need to use TimeValue.

    Can anyone point me in the right direction?

    Thanks


    startTime
    18
    14.3
    18


    19.4
    19.2
    19.2
    13.3
    18
    14.3
    18
    18
    18
    18
    10
    14.3
    14.3
    18
    18
    18
    18
    14.3
    14.3
    18
    18
    18
    18
    10
    14.3
    18
    18
    18
    18
    18
    14.3
    14.3
    14.3
    18
    18
    19
    15
    15
    19
    19.4
    19.1
    19.4
    18.1
    18.15
    19.1
    19.1
    19.1
    19.1
    18.1
    18.4
    18.1
    18.15
    19.1
    18.1
    19.1
    16.1
    18.4
    19.1
    19.1
    19.4
    19.4
    18.4
    19.4
    18.1
    18.15
    19.1
    19.4
    19.4
    18.4
    16.2
    19.25

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    Do those represent the hour of the day? For starters, your SQL is using today's date, not the field value. Perhaps:

    CDate(ConvDate / 24)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    also need to clarify whether 14.3 id 2:30pm or 2:20pm

  4. #4
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35
    Thanks guys. Apologies, my post wasn't clear.

    startTime is a separate field to Date. I've tried
    Code:
    CurrentDb.Execute "UPDATE Matches SET Matches.ConvTime = CDate(startTime / 24)", dbFailOnError
    but I get a 3061 error saying too few parameters.

    Ajax, 14.3 is 2.30. And 18 is 6.00

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    "doesn't work" doesn't really help. In what way doesn't it work? If 14.3 is 2:30, you're probably going to need to parse the data. Anything left of the decimal plus ":" plus anything right of the decimal. I might create a public function that took the string as an input and returned a date/time.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35
    Hi Paul,

    I think I must have been editing my post when you posted.

    It is a 3061 error saying too few parameters that I get.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    Likely either something is spelled wrong or one of the fields specified doesn't exist in that table. Basically that's Access telling you it can't find something.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35
    Thanks Paul. That must be the empty fields.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    If so you could add a criteria:

    CurrentDb.Execute "UPDATE Matches SET Matches.ConvTime = CDate(startTime / 24) WHERE startTime Is Not Null", dbFailOnError

    That assumes they don't have a zero length string in them.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    Ajax, 14.3 is 2.30
    in which case your formula won't provide the right time

    ?cdate(14.3/24)
    14:18:00

    ?cdate(19.25/24)
    19:15:00


    you need to use something like this to covert .3 to 30 minutes

    ?cdate(format(14.3,"0.00"))
    14:30:00

    ?cdate(format(19.25,"0.00"))
    19:25:00

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    Interesting, I wouldn't have expected the Format() function to affect the CDate() like that. Apparently it makes assumptions based on the string.

    ?cdate("14.30")
    2:30:00 PM
    ?cdate("14.3")
    2:03:00 PM
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    robsmith is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Feb 2020
    Posts
    35
    Thanks for all your help with this guys. I couldn't get anything to work unfortunately but have come up with a workaround. Thanks again.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Changing short text field to date/time field
    By fishhead in forum Access
    Replies: 5
    Last Post: 03-25-2020, 01:17 AM
  2. Replies: 5
    Last Post: 08-10-2018, 02:20 PM
  3. Converting Hyperlink field back to short text
    By gksmith5 in forum Access
    Replies: 3
    Last Post: 06-02-2018, 01:19 AM
  4. Replies: 7
    Last Post: 04-07-2017, 02:08 AM
  5. Converting time from text to time
    By virgilwilsonjr in forum Access
    Replies: 4
    Last Post: 01-11-2013, 10:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums