[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

Date conversion

Why can't I convert a string of format #mm/dd/ccyy" to a date variable?

Dim dTmpDate as Long
Dim strDate as String

strDate = "#" & "03/21/2006" & "#"
dTmpDate = CDate(strDate)

Error: Type conversion

0
swansonplace
Asked:
swansonplace
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
EDDYKTCommented:
strDate = "03/21/2006"
0
 
cubixSoftwareCommented:
You have declared dTmpDate as long

try Dim dTmpDate as Date

0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>Dim dTmpDate as Long
Because you have this as a Long, to convert to a date Variable start with...
Dim dTmpDate as Date
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
You can also do some validating like this...

If Isdate(strDate)
   dTmpDate = CDate(strDate)
else
   msgbox "strDate is not a valid Date.  Handle this gracefully."
end if
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Questions, comments...
0
 
ptan218Commented:
This code will work for you.

Dim dTmpDate as DATE       ';<-- CHANGE DATATYPE TO DATE
Dim strDate as String

strDate = "03/21/2006"   '<--- DO NOT PUT POUND SIGN HERE. IT ONLY WORKS IN ACCESS
dTmpDate = CDate(strDate)
0
 
EDDYKTCommented:
don't think you need to change to

Dim dTmpDate as DATE      

since if you not deal with hour and second, it should be number and not decimal number
0
 
cubixSoftwareCommented:
...are we done here?
0
 
cubixSoftwareCommented:
Dan - I think the points should be split between myself (for my first reply) and to jimhorn for his IsDate reply
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now