Results 1 to 11 of 11
  1. #1
    Hswift is offline Novice
    Windows 8 Access 2013
    Join Date
    Dec 2015
    Posts
    20

    How to add Decimals, Colons and Slashes to numbers in columns?

    Hello, I have three columns in a table with numbers that look like this.

    datecolumn timecolumn pricecolumn
    20151201 190006176 206350
    20151201 190832820 206000
    20151201 190832824 206025


    Any suggestions on how I can convert the numbers to look like this?

    datecolumn timecolumn pricecolumn
    2015/12/01 19:00:06.176 2063.50
    2015/12/01 19:08:32.820 2060.00


    2015/12/01 19:08:32.824 2060.25


    thanks!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Assign appropriate data type is basic answer. Date/Time double with decimal places
    How do you know that 2015/12/01 is a date? Default for Access is US presentation MM/DD/YYYY

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I agree. Why is this string data and not appropriate field types?

    Converting will require string manipulation to rearrange the parts for the date and time values.

    The price can be converted to a number with: Val([pricecolumn])/100

    This assumes the rightmost 2 characters will always be decimal part and that no record has Null in this field.


    AFAIK, Access cannot work with decimal seconds in actual time values.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Hswift is offline Novice
    Windows 8 Access 2013
    Join Date
    Dec 2015
    Posts
    20
    Hi Orange,

    Is this something I do via selecting the "Query Design" tool then selecting the "SQL View"?

    Can you please type out a code example for me if so?

    Thanks!

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    No, I think orange is suggesting the table fields should have correct data types then populate the fields.

    I just tried Format() function with the date value and it does modify the format: Format([datefield], "0000/00/00")

    However, this is not a true date and cannot be used in date calculations.

    I cannot get Format() to work on the time value unless I drop the decimal seconds: Format(Left([timefield],6),"00:00:00")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    as a direct answer to your question google using the left, right and mid string functions

    however whether this does what you really require is another question - if you actually want to end up with a date field, a time field (or perhaps a datetime field) and a currency field, then this is what you need to ask

  7. #7
    Hswift is offline Novice
    Windows 8 Access 2013
    Join Date
    Dec 2015
    Posts
    20
    Its fine for my needs if Access only recognizes the data in these three columns as numbers (rather then actual dates or times).

    Does this bring up any new ideas on how i can do the conversion?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I have provided expression that will convert the price to a number.

    I have provided expressions that will modify the structure of the date and time values but the results will still be a string, not actual date and time values. If you need date and time values, try:

    CDate(Format([datefield],"0000/00/00"))

    CDate(Format(Left([timefield],6),"00:00:00"))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Hswift is offline Novice
    Windows 8 Access 2013
    Join Date
    Dec 2015
    Posts
    20
    Thanks June7, where would I type this code in exactly?

    I clicked the "Query Design" tab then clicked the "Sql View" and entered the code, but it did not seem to work.
    Did I just type it in wrong? Or am I supposed to add this code somewhere else entirely?

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    The expressions can be used in query to construct fields http://www.fontstuff.com/access/acctut02.htm or in textbox ControlSource property.

    This is basic Access functionality. Completing an introductory tutorial book or online course would probably be a big help in your understanding of Access.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Hswift is offline Novice
    Windows 8 Access 2013
    Join Date
    Dec 2015
    Posts
    20
    Ahh, that http://www.fontstuff.com/access/acctut02.htm link definitely explained how to construct the fields, simpler than i thought. Thanks for everything everyone!

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

Similar Threads

  1. Rounding decimals
    By brianmcleer in forum Access
    Replies: 1
    Last Post: 06-05-2013, 12:37 PM
  2. Comparing Columns of numbers with IIf function
    By emspence in forum Queries
    Replies: 7
    Last Post: 02-23-2013, 01:05 AM
  3. Age with Decimals?
    By Lowell in forum Access
    Replies: 1
    Last Post: 10-18-2012, 11:13 PM
  4. Replies: 3
    Last Post: 10-04-2012, 11:38 AM
  5. Round Up/Down 4 Decimals to 2
    By newbie in forum Access
    Replies: 6
    Last Post: 10-18-2010, 02:58 PM

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