Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to split date string in access?

Status
Not open for further replies.

ugly

Programmer
Jul 5, 2002
70
0
0
GB
Unable to split date string in access?

I need to split a date that is in the the form of a string, they must be declared as strings and not dates. The problem is that I cannot extract the day using day(dateStr), month(dateStr) and year(dateStr). These funtions produce a type error 13 type mismatch.


Dim dateStr As String
Dim dateStr2 As String

'dateStr2 = hold1 & "/" & hold2 & "/" & hold3
dateStr2 = "01/12/2008"
dateStr = Format(dateStr2, "dd/mm/yyyy")
Debug.Print day(dateStr)
 
You are so close to the solution, you know:

The day function expects a date, not a string.
This works fine for me:
Code:
Sub test()

Dim daystr As Date
Dim daystr2 As String

daystr2 = "11.02.2008"
daystr = CDate(daystr2)

MsgBox Day(daystr)

End Sub

;-)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Hi Thanks for you help tried this but still failling
Dim daystr As Date
Dim daystr2 As String

daystr2 = "11/02/2008"
daystr = CDate(daystr2)

MsgBox day(daystr) is failling here mismatch error
 
???

It does work on my side.
Is this all your code, or are you hiding a bit? Be honest!
:p

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Many thanks yes I was using 31 on a month that doesn't have 31!!! Thanks!
 
Ah yes, this sounds familiar... :-D

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top