473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Convert String to Date

I need to convert a string "20040129" to a date format "01/29/2004". How do you do this?
Jan 22 '08 #1
4 26225
missinglinq
3,532 Expert 2GB
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
8,834 Expert 8TB
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
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
8,834 Expert 8TB
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

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

Similar topics

13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
2
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a...
2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
6
by: vunet.us | last post by:
How can I convert UTC time such as 1173451235415 to a local time I can read? Thank you
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
4
by: =?Utf-8?B?YW5kcmV3?= | last post by:
I am running an ASP.net program written in VB. At one point I try to convert a date string into a date time object... this string is from a central dev server and the code works on many other...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.