473,378 Members | 1,152 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,378 software developers and data experts.

IsDate in C#

In VB6 there is a function IsDate that returns True if the expression is of type Date or is a string convertible to type Date; otherwise, it returns False. Is there such a built-in function in C#?
Thanks.
Nov 17 '05 #1
2 25961
> Wayne wrote:

In VB6 there is a function IsDate that returns True if the expression is of
type Date or is a string convertible to type Date; otherwise, it returns
False. Is there such a built-in function in C#?
Thanks.


You can use the DateTime.Parse() method. If it throws an exception, it isn't a
date:

try
{
System.DateTime dt = System.DateTime.Parse(str);
}
catch
{
// Not a date, handle appropriately
}
Nov 17 '05 #2
Thanks Julie! It works great.
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
Wayne wrote:

In VB6 there is a function IsDate that returns True if the expression is of type Date or is a string convertible to type Date; otherwise, it returns
False. Is there such a built-in function in C#?
Thanks.
You can use the DateTime.Parse() method. If it throws an exception, it

isn't a date:

try
{
System.DateTime dt = System.DateTime.Parse(str);
}
catch
{
// Not a date, handle appropriately
}

Nov 17 '05 #3

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

Similar topics

4
by: Vladislav | last post by:
Could somebody comment the folowing log from immediate panel: ? isdate("0A0-0002") True ? cdate("0A0-0002") 01/02/2000 I would expect the value "0A0-0002" as not date
0
by: vonclausowitz | last post by:
Hi All, I use IsDate() to check a field in Outlook tasks to see if it contains a real date. If IsDate(Task.role) then ... else ... endif
2
by: EP | last post by:
I just upgraded a V 6.0 app. to .Net. I keep getting an error from a simple IsDate statement. Basically checking to see if the value of a variable(vValue = "A2957") is a date example - If...
4
by: John A Grandy | last post by:
IsNumeric() and IsDate() are "leftovers" from the VB6 days ... looking forward, perhaps it would be better not to use them .... does anyone have suggestions on replacements ?
1
by: Sebastian Santacroce | last post by:
Hi, I am trying to use IsDate where the application will use a format of Month/day/year however on a system that uses day/month/year then IsDate uses that system format setting when evaluating if...
2
by: Oenone | last post by:
I'm having a couple of problems with the IsDate function in VB.net (.net framework v1.1). Having searched the web and usenet for others having the same problem, I've seen several posts from people...
2
by: z. f. | last post by:
Hi, i see in reflector in inner implementation of the Microsoft.VisualBasic.Information.IsDate function that looks like that: public static bool IsDate(object Expression) { if (Expression !=...
5
by: Jack Russell | last post by:
Why does IsDate("01:01:0_") return true?? Thanks Jack Russell
19
by: MDC | last post by:
Why does this return true: IsDate("ISometimesHateProgrammingMarch2005") Is there another way to verify that this is not a date?? Thanks in advance! MDC
1
by: nlulla | last post by:
Hi I am trying to get all rows from a datatable where the first column F1 is a date, as this datatable is created of excel, i only want to deal with rows where the first column is having a date in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.