473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Check to see if a value is a DateTime

Hello all,

I've written the below but am aware it's not the best way to do it. Does
anyone have any other example please? The method simply checks to see if the
value is a date.

try
{
p.Value = DateTime.Parse(coll.Get(i)).ToString("yyyy-MM-dd");
}
catch
{
p.Value = coll.Get(i);
}

Thanks all,

Jon
Mar 28 '07 #1
2 1282
Use the TryParse method of the DateTime class.

Here's more info:
http://msdn2.microsoft.com/en-us/library/ch92fbc1.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

"Jon" <Jo*@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.com...
Hello all,

I've written the below but am aware it's not the best way to do it. Does
anyone have any other example please? The method simply checks to see if
the
value is a date.

try
{
p.Value = DateTime.Parse(coll.Get(i)).ToString("yyyy-MM-dd");
}
catch
{
p.Value = coll.Get(i);
}

Thanks all,

Jon
Mar 28 '07 #2
On Mar 28, 12:58 am, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
howdy

dim date as String = String.Empty
dim value as Object = coll.Get(i)

if typeof value is DateTime then
date = CType(value, DateTime).ToString("yyyy-MM-dd")
end if

hope this helps
--
Milosz
VB.Net has an IsDate() function that checks if the value is a date.

Mar 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Abdolhosein Vakilzadeh Ebrahimi | last post by:
Is there any way to construct a System.DateTime which doesn't check year, month and day to be in correct range== no validation? Thanks A.V.Ebrahimi
5
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! When reading a value from an SQL database i get to a DateTime variable... How can i check that the there is no value assigned? Since i cant use if(myDate.ShortDate != null) ? Regards
4
by: Michael C# | last post by:
Given a DateTime variable, what's the best way to check "minor" status (i.e., less than age 18 years) based on today's date? I came up with this: Dim minor As Boolean = true 'dtDOB is a...
1
by: Philip Wagenaar | last post by:
I have an XML file that has a date element. I want to change this date to unix notation. This works, but if the XML does not have the element I cannot assign the DateField the value. How can I...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
1
by: Thomas | last post by:
Hi all, i have to check if a value is a valid date format depending on a "format string" the user specified. For example: Format String: "dd/mm/yyyy" Date Value: "01/12/2006" Valid: Yes! ...
1
by: Rich | last post by:
Hello, I have been adding a handler to the TextBox.Leave event to check if a value that is entered in a Date Textbox is a Date. This works OK. But I am just checking if there is anything...
7
by: geo039 | last post by:
I have a simple application that takes user input by text and time selected by date time picker. It displays the appt description in one list box and the time in another list box. I need a simple...
3
by: Mike P | last post by:
How would I check a datetime variable is within the last 7 days? *** Sent via Developersdex http://www.developersdex.com ***
7
by: hatch | last post by:
The project I am working on has to have start and stop buttons on a form and a label to show the eslaped time once the start button is pushed. The elapsed tome should stop when the stop button is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.