p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   convert string to datetime in VB.net (http://p2p.wrox.com/showthread.php?t=58959)

lisabb June 11th, 2007 08:17 PM

convert string to datetime in VB.net
 
I have two text fields that the user can enter a begin and end time in format 1200 (ex: 0100 and 1100). I am trying to convert it into a proper datetime to send to sql server. I have tried the code below but it always tells me that it is not a proper datetime format. It looks correct when I do a msgbox to see what I am passing so I can't figure out what I am doing wrong. Can someone look at this and help me?

Thanks
Lisabb


invtxtBetweenTimeFirst.Text = txtBetweenTimeFirst.Text.Substring(0, 2) + ":" + txtBetweenTimeFirst.Text.Substring(2, 2) + ":" + "00"

invtxtBetweenTimeSecond.Text = txtBetweenTimeSecond.Text.Substring(0, 2) + ":" + txtBetweenTimeSecond.Text.Substring(2, 2) + ":" + "00"

invtxtBetweenTimeFirst.Text = "1900 -01 -01" + TimeValue(invtxtBetweenTimeFirst.Text)

invtxtBetweenTimeSecond.Text = "1900-01-01" + TimeValue(invtxtBetweenTimeSecond.Text)

invtxtBetweenTimeFirst.Text = Convert.ToDateTime(invtxtBetweenTimeFirst.Text)

invtxtBetweenTimeSecond.Text = Convert.ToDateTime(invtxtBetweenTimeSecond.Text)

thandermax June 14th, 2007 12:25 AM

may be the time separator in ur compu is "/" instead of ":" or something else.

Your year string (i think ) should be in this format : "MM/DD/YYYY" .
then add a space and time in format "xx:yy AM/PM"



ABhattacharyya

webguru June 19th, 2007 12:46 AM

This did not work for me... Visual Studio shows me this format:
convert.ToDateTime(value as Date) as Date

This does not make sense - why would I need to convert Date to Date..???

banoo June 19th, 2007 06:52 AM

string stime,etime;
            stime = t1.Text.Substring(0,2)+":"+t1.Text.Substring(2,2)+ ":"+"00";
            etime = t2.Text.Substring(0,2)+":"+t2.Text.Substring(2,2)+ ":"+"00";

            t3.Text = Convert.ToDateTime("01/01/1900 " + stime + "AM").ToString();
            t4.Text = Convert.ToDateTime("01/01/1900 " + stime + "AM").ToString();

Try this.... Working


All times are GMT -4. The time now is 01:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.