By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,059 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,059 IT Pros & Developers. It's quick & easy.

Convert String to Date

P: 78
I need to convert a string "20040129" to a date format "01/29/2004". How do you do this?
Jan 22 '08 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
Assuming your string is always formatted this way

YourDate = Mid(YourString,5,2) & "/" & Right(YourString,2) & "/" & Left(YourString,4)


Linq ;0)>
Jan 22 '08 #2

ADezii
Expert 5K+
P: 8,679
I need to convert a string "20040129" to a date format "01/29/2004". How do you do this?
There may be an easier Method, but off the top-of-my-head, the folowing code snippet will convert the String "20040129" to a True Date with the Format mm/dd/yyyy:
Expand|Select|Wrap|Line Numbers
  1. Dim strDate As String, dteConvertedDate As Date
  2.  
  3. strDate = "20040129"
  4.  
  5. dteConvertedDate = CDate(Mid$(strDate, 5, 2) & "/" & Right$(strDate, 2) & "/" & Left$(strDate, 4))
  6.  
  7. Debug.Print dteConvertedDate
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. 1/29/2004
Jan 22 '08 #3

P: 78
Assuming your string is always formatted this way

YourDate = Mid(YourString,5,2) & "/" & Right(YourString,2) & "/" & Left(YourString,4)


Linq ;0)>

I got this to work in the query, then I used "CDATE" to convert it to a date. Now I need to add a Where Clause so I can limit it down to the date period I need but the query keeps coming up blank when I add parameters Between [StartDate] and [EndDate].....Any help would be useful.
Jan 22 '08 #4

ADezii
Expert 5K+
P: 8,679
I got this to work in the query, then I used "CDATE" to convert it to a date. Now I need to add a Where Clause so I can limit it down to the date period I need but the query keeps coming up blank when I add parameters Between [StartDate] and [EndDate].....Any help would be useful.
Are [StartDate] And [EndDate] Date data type Fields? If so, and you are still having the problem, post the SQL.
Jan 23 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.