heng03
asked on
CDate conversion error
Hi
I have a textbox ticketDate.text which have value "21-10-2003".
I used the CDate function to conversion it :- CDate(ticketDate.Text) but have
run time error.
Cast from string "21-10-2003" to type "Date" is not valid.
Pls help
Thanks & Rgds
Heng03
I have a textbox ticketDate.text which have value "21-10-2003".
I used the CDate function to conversion it :- CDate(ticketDate.Text) but have
run time error.
Cast from string "21-10-2003" to type "Date" is not valid.
Pls help
Thanks & Rgds
Heng03
ASKER
Hi mmarinov
Your suggestion have syntax error.
Thanks & Rgds
Heng03
Your suggestion have syntax error.
Thanks & Rgds
Heng03
ASKER
Hi mmarinov
Your suggestion have syntax error & compilation error.
It do not work.
Thanks & Rgds
Heng03
Your suggestion have syntax error & compilation error.
It do not work.
Thanks & Rgds
Heng03
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use a datetimepicker control, it's easier and user friendly.
ASKER
Hi
Sweet! Thanks!
- Marc
- Marc
heng03:
Thanks for the points!
Just out of curiosity, how does your corrected code look like?
Dabas
Thanks for the points!
Just out of curiosity, how does your corrected code look like?
Dabas
ASKER
Hi everyone
I used the sample code from MarcGraff, it is the best for my situation.
My code is below.
dim TmpStr() As String
TmpStr = Split(txtTicketDate.Text, "-")
Try
TicketDate = CDate(TmpStr(1) & "-" & TmpStr(0) & "-" & TmpStr(2))
Catch
validYes = False
errMsg &= "Error Ticket Date : Shall be dd-mm-yyyy. Please try
again." + vbNewLine
End Try
The reason is that, it re-substring my date from dd/mm/yyyy to mm/dd/yyyy which is
suitable for the us-EN culture date-time format ("d").
As such, the CDate(expression) will work fine. else error if format is dd/mm/yyyy.
Thanks & Rgds
Heng03
I used the sample code from MarcGraff, it is the best for my situation.
My code is below.
dim TmpStr() As String
TmpStr = Split(txtTicketDate.Text, "-")
Try
TicketDate = CDate(TmpStr(1) & "-" & TmpStr(0) & "-" & TmpStr(2))
Catch
validYes = False
errMsg &= "Error Ticket Date : Shall be dd-mm-yyyy. Please try
again." + vbNewLine
End Try
The reason is that, it re-substring my date from dd/mm/yyyy to mm/dd/yyyy which is
suitable for the us-EN culture date-time format ("d").
As such, the CDate(expression) will work fine. else error if format is dd/mm/yyyy.
Thanks & Rgds
Heng03
ASKER
Hi everyone,
I increased the points from 50 to 75.
And split among 3 of you. Each 25 points.
Sorry for that.
Thanks & Rgds
Heng03
I increased the points from 50 to 75.
And split among 3 of you. Each 25 points.
Sorry for that.
Thanks & Rgds
Heng03
CDate uses standarts for datatimeformats
if you want to use your custom format you can use ticketDate.Text.ToString("
B..G