Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 11th, 2007, 08:17 PM
Authorized User
Join Date: May 2007
Location: Fairfax, va, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?


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)
Reply With Quote
  #2 (permalink)  
Old June 14th, 2007, 12:25 AM
Authorized User
Join Date: Aug 2004
Location: KOL, WB, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

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"

Reply With Quote
  #3 (permalink)  
Old June 19th, 2007, 12:46 AM
Registered User
Join Date: Jun 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

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..???
Reply With Quote
  #4 (permalink)  
Old June 19th, 2007, 06:52 AM
Registered User
Join Date: Jun 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

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
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert String to DateTime SimoNWellborne C# 3 October 11th, 2014 02:24 AM
How to convert a string in DateTime elena SQL Language 6 March 29th, 2006 06:59 PM
Convert string to datetime nkovacevic General .NET 4 April 5th, 2005 11:57 AM
VB.NET: Convert String and append to Xml files toytoy Pro VB.NET 2002/2003 0 September 2nd, 2004 10:50 PM
How to convert a string in DateTime elena ADO.NET 3 July 24th, 2003 04:31 PM

All times are GMT -4. The time now is 10:33 PM.

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