|
-
Apr 27th, 2005, 02:02 PM
#1
Thread Starter
Addicted Member
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.
-
Apr 27th, 2005, 02:11 PM
#2
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
-
Apr 27th, 2005, 02:14 PM
#3
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.
-
Apr 27th, 2005, 02:27 PM
#4
Thread Starter
Addicted Member
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.
-
Apr 27th, 2005, 04:30 PM
#5
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 ...
-
Apr 27th, 2005, 04:32 PM
#6
Thread Starter
Addicted Member
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.
-
Apr 27th, 2005, 05:37 PM
#7
Addicted Member
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:
Option Explicit
Const src = "0120:10"
Private Sub Command1_Click()
Dim d As Date
Dim s() As String
s = Split(src, ":")
d = (CSng(s(0)) / 1440) + (CSng(s(1)) / 86400)
MsgBox d
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.
-
Apr 28th, 2005, 10:03 AM
#8
Thread Starter
Addicted Member
Re: String to Date conversion
Thanks, I didn't of converting it into days, but it works.
-
Apr 28th, 2005, 11:02 AM
#9
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|