Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2007, 08:17 PM
Authorized User
 
Join Date: May 2007
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?

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)
 
Old June 14th, 2007, 12:25 AM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old June 19th, 2007, 12:46 AM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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..???
 
Old June 19th, 2007, 06:52 AM
Registered User
 
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





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





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