Results 1 to 9 of 9

Thread: String to Date conversion [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Resolved String to Date conversion [RESOLVED]

    I have a string in the format of "MMMM:SS" that I import into MS Access that I would like to convert into a 'Date/Time' format and I'm not sure how to do it. Is it possible to do this and use my MMMM:SS format?
    Last edited by bat711; Apr 28th, 2005 at 10:04 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: String to Date conversion

    Let me know if the link below helps you, have a look at the conversion functions.

    http://www.vbforums.com/showthread.php?t=316508

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: String to Date conversion

    "MMMM:SS" is very unusual format so I'm afraid you cannot convert it back to "normal" date and/or time. Sorry.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: String to Date conversion

    Well I guess this isn't really a "VB" question, but currently I'm just sending the string as text through SQL. I am trying to work with the data in Excel as well, but I'm having trouble since it is in a "Text" format I can't do mathematical calculations on it. So maybe I need to look for something in Excel to convert it.

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: String to Date conversion

    It doesn't really matter "where" - what you have is MONTH:SECONDS format so what are going to do with that? You cannot convert it to current date/time nor you can get day/year/hour/minutes from it ...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: String to Date conversion

    It's in a format of Minutes:Seconds, I'd just like to change it to something besides a text string so that I can do calculations with it. Excel has several formats that are similar to this and would be useful but it won't convert it. Ithink I may just not be able to change what I have.
    Last edited by bat711; Apr 28th, 2005 at 09:45 AM.

  7. #7
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: String to Date conversion

    I'm not a date specialist at all, but using simple maths and string parsing it's not that hard to get. Here's a sample code:

    VB Code:
    1. Option Explicit
    2. Const src = "0120:10"
    3.  
    4. Private Sub Command1_Click()
    5.  
    6. Dim d As Date
    7. Dim s() As String
    8.  
    9. s = Split(src, ":")
    10. d = (CSng(s(0)) / 1440) + (CSng(s(1)) / 86400)
    11. MsgBox d
    12.  
    13. End Sub

    I haven't tested it except on a few values, but it should work.
    Last edited by Max_aka_NOBODY; Apr 27th, 2005 at 05:45 PM.
    Please, put a checkmark ( ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Thumbs up Re: String to Date conversion

    Thanks, I didn't of converting it into days, but it works.

  9. #9
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: String to Date conversion [RESOLVED]

    Not sure if I understood you write, but it does convert to days, so "4320:35" would be converted to [30/12/1899 + 3 days + 35 seconds]. 30/12/1899 is the lowest boundary for dates, and is equal to 0.
    Please, put a checkmark ( ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.

Posting Permissions

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



Click Here to Expand Forum to Full Width