|
-
Jul 25th, 2011, 09:55 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] taking specific value using string manipulation function
can someone tell me ?how should i take only time part using left,right,Mid
function .any help would be highly appreciated.
Code:
7/23/2011 11:40:00 PM
7/23/2011 11:40:00 PM
7/23/2011 11:40:00 PM
7/24/2011 10:41:01 AM
7/24/2011 12:40:27 PM
7/24/2011 12:42:34 PM
7/24/2011 2:08:28 PM
7/24/2011 2:08:28 PM
7/24/2011 2:08:28 PM
7/24/2011 2:08:28 PM
7/24/2011 2:08:28 PM
7/24/2011 2:30:58 PM
7/24/2011 3:59:24 PM
7/24/2011 5:35:10 PM
7/24/2011 5:56:08 PM
7/24/2011 5:56:36 PM
7/24/2011 5:56:36 PM
7/24/2011 7:00:55 PM
7/24/2011 7:00:55 PM
7/24/2011 7:00:55 PM
7/24/2011 7:00:55 PM
7/24/2011 8:33:40 PM
7/24/2011 8:33:40 PM
7/24/2011 9:30:25 PM
7/24/2011 9:31:42 PM
7/24/2011 9:50:54 PM
-
Jul 25th, 2011, 10:03 AM
#2
Re: taking specific value using string manipulation function
I guess you mean something like this:
DateAndTime = "7/23/2011 11:40:00 PM"
TimePart = Mid(DateAndTime, 11)
however, if month will have 2-digits then
TimePart = Mid(DateAndTime, 12)
Last edited by jmsrickland; Jul 25th, 2011 at 10:07 AM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 25th, 2011, 10:30 AM
#3
Re: taking specific value using string manipulation function
There could be several approaches, although most of them would use Mid$:
Code:
Option Explicit
Private Sub Command1_Click()
Dim myDateTime As String
Dim myParts() As String
Dim myTime As String
myDateTime = "7/24/2011 9:50:54 PM"
'method 1
myTime = VBA.Mid$(myDateTime, VBA.InStr(1, myDateTime, Space(1)) + 1)
Debug.Print myTime
'method 2
myTime = VBA.Mid$(Format(myDateTime, "mm/dd/yyyy h:nn:ss AM/PM"), 12)
Debug.Print myTime
'method 3
myParts = VBA.Split(myDateTime, VBA.Space$(1))
myTime = myParts(1) & Space(1) & myParts(2)
Debug.Print myTime
'etc...
End Sub
-
Jul 25th, 2011, 10:33 AM
#4
Re: taking specific value using string manipulation function
If you can think outside the box, the format function will work well for you.
Code:
Private Sub Command1_Click()
Dim strDateTime As String
strDateTime = "7/23/2011 11:40:00 PM"
MsgBox GetTime(strDateTime)
End Sub
Private Function GetTime(ByVal DateTime As String) As String
Dim dteInput As Date
dteInput = CDate(DateTime)
GetTime = Format(dteInput, "HH:NN:SS AM/PM")
End Function
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
|