Hi all,
I am trying to read an integer value as a date into a sql database. One example value would be 80410 where 8 is the yr, 04, the month and 10 is the day. How can I do this?
Thanks
Hi all,
I am trying to read an integer value as a date into a sql database. One example value would be 80410 where 8 is the yr, 04, the month and 10 is the day. How can I do this?
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
ghazanfar khanPosted May 29, 2008, 4:35 PM
Thanks Dipal. I ended up reading it into a string first like you suggested as well. And Thank you for pointing out that feeding 2 "0"s before the yr digit would be a problem after 2009! I have made a note tro address that issue in 2009...lol. kidding
cheers
ghazanfar khanPosted May 29, 2008, 4:31 PM
Thanks James, I couldnt follow too well, but this is what I ended up doing
SMPL_DTEstr = SMPL_DTEstr.Chars(1) + SMPL_DTEstr.Chars(2) +
"/" + SMPL_DTEstr.Chars(3) + SMPL_DTEstr.Chars(4) + "/" + "200" + SMPL_DTEstr.Chars(0)SMPL_DTE = Convert.ToDateTime(SMPL_DTEstr)
and it works. Hopefully it wont break over unsual conditions like the ones pointed out below.
Thanks for the help!
Dipal ChoksiPosted May 20, 2008, 5:17 PM
Niradhip ChakrabortyPosted May 20, 2008, 5:02 PM
Dim intDateFormat As Integer
Dim strDateFormat As String
Dim strYear As String
Dim strMonth As String
Dim strDate As String
Dim strDate1 As String
Dim strDate2 As String
Dim strprefix As String
Dim strfinal As String
intDateFormat = 80517
strDateFormat = CType(intDateFormat)
strYear = strDateFormat.Substring(0, strDateFormat.Length - 4) 'this give you value 8
strMonth = strDateFormat.Substring(1, strDateFormat.Length - 3) 'this give you value 05
strDate = strDateFormat.Substring(1, strDateFormat.Length - 1) 'this give you value 0517
strDate1 = strDate.Substring(1, strDate.Length - 1) 'this give you value 517
strDate2 = strDate1.Substring(1, strDate1.Length - 1) 'this give you value 17
strprefix = "200"
strfinal = strprefix & strYear & "/" & strMonth & "/" & strDate2
Now pass this strFinal value to database,your strfinal will contents 2008/05/17
ghazanfar khanPosted May 20, 2008, 2:46 PM
In other words, the first digit is the year to which I have to add the prefix "200" the next 2 digits are the month and last 2, the day.
Thanks!
ghazanfar khanPosted May 20, 2008, 2:28 PM
Niradhip ChakrabortyPosted May 20, 2008, 2:22 PM