How do I check for a valid datetime, where both the date and the time
must be entered in the format DD/MM/YYYY HH:MM? Using
Convert.ToDateTime would work
even if a time is not added so I can't use this?
*** Sent via Developersdex http://www.developersdex.com *** 6 2121
"Mike P" <mi*******@gmail.comwrote:
How do I check for a valid datetime, where both the date and the time
must be entered in the format DD/MM/YYYY HH:MM?
DateTime.ParseExact.
I think your format string will be "dd/MM/yyyy HH:mm"
Eq.
Another approach; parse it, and then call ToString() specifying the
format you expected. If the "before" and "after" strings aren't the
same, then the input wasn't valid.
Marc
On Jun 3, 9:50 am, "Paul E Collins" <find_my_real_addr...@CL4.org>
wrote:
"Mike P" <mike.p...@gmail.comwrote:
How do I check for a valid datetime, where both the date and the time
must be entered in the format DD/MM/YYYY HH:MM?
DateTime.ParseExact.
Or DateTime.TryParseExact for checking purposes.
I think your format string will be "dd/MM/yyyy HH:mm"
Agreed.
Jon
In this code example I have found, what classes do I need to reference
to get at DateTimeFormatInfo and DateTimeStyles objects?
DateTime validatedDate;
bool valid = DateTime.TryParseExact(date, date_format,
DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out
validatedDate);
*** Sent via Developersdex http://www.developersdex.com ***
On Jun 3, 10:57 am, Mike P <mike.p...@gmail.comwrote:
In this code example I have found, what classes do I need to reference
to get at DateTimeFormatInfo and DateTimeStyles objects?
DateTime validatedDate;
bool valid = DateTime.TryParseExact(date, date_format,
DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out
validatedDate);
I think you mean the namespace - and System.Globalization is what
you're after.
If you just write the code above though, and put the edit caret in
DateTimeStyles or DateTimeFormatInfo, then hit Ctrl-period, it should
offer to import the right namespace for you. This can be a real time-
saver.
Jon
On Jun 3, 5:57*am, Mike P <mike.p...@gmail.comwrote:
In this code example I have found, what classes do I need to reference
to get at DateTimeFormatInfo and DateTimeStyles objects?
DateTime validatedDate;
bool valid = DateTime.TryParseExact(date, date_format,
DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out
validatedDate);
*** Sent via Developersdexhttp://www.developersdex.com***
Hi,
If you want to know the namespace of a class all you have to do is
type it in MSDN lib, you will get it in the "About" section.
Those classes are in System.Globalization BTW This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Maksim Kasimov |
last post by:
there are few of a time periods, for example:
2005-06-08 12:30 -> 2005-06-10 15:30,
2005-06-12 12:30 -> 2005-06-14 15:30
and there is some date and time value:
2005-06-11 12:30
what is the...
|
by: JackO |
last post by:
I have a text box on a form “txtExamDate” that I know contains nothing. I am
trying to test code that will determine the text box is nothing. I am
getting the error because there is no value...
|
by: andrewcw |
last post by:
I save date time into my XML files like this:
MesObj.theTime=System.DateTime.Now;
"5/4/2004 8:50:30 AM"
BUT that string is NOT recognizable as a valid
dateTime when the data is read back from...
|
by: William Stacey [MVP] |
last post by:
Given a day of the month (<=31) how to calculate if that day is valid for
all months up to some end date or DateTime.MaxValue? TIA
--
William Stacey, MVP
|
by: craigkenisston |
last post by:
Hi,
I create a one day ticket in my authentication code like this :
private void btnLogin_Click(object sender, System.EventArgs e)
{
string _userId = txtUserId.Text;
string _password =...
| |
by: SQLScott |
last post by:
I have created a VB.Net app that takes data from Visual Foxpro and inserts it
into SQL Server.
The problem I am running into is that I have come across records in Foxpro
where the dates are as...
|
by: Bob Day |
last post by:
The IsDate code below should result in False, instead it throws the
exception below. Why? How do I check if a string can be converted to a
date if this function does not work properly?
Bob
...
|
by: romy |
last post by:
What's the easiest way to verify the user had entered a valid date ?
|
by: database |
last post by:
I AM FACING A PROBLEM WHEN I ACCESS ONE OF THE PAGES. IT USED TO WORK
BEFORE BUT AFTER RESTARTING THE APPLICATION SEVER IT GIVES THE FOLLOWING
ERROR.
- Server Error
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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 projectplanning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |