455,059 Members | 1,171 Online
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
4 Replies

 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

 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 Dim strDate As String, dteConvertedDate As Date   strDate = "20040129"   dteConvertedDate = CDate(Mid\$(strDate, 5, 2) & "/" & Right\$(strDate, 2) & "/" & Left\$(strDate, 4))   Debug.Print dteConvertedDate OUTPUT: Expand|Select|Wrap|Line Numbers 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

 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