I am trying to set a date in a DateTime variable that I get from a user:
DateTime theDate;
theDate = "08-15-05";
This gives me an error:
Cannot implicitly convert type 'string' to 'System.DateTime'
How do I set it?
I then want to compare it to see if it is equal to another string variable
that is also a date:
if theDate = stringDate...
How do I do this with the DateTime variable?
Thanks
Tom 9 2993
Try this..
theDate =System.DateTime.Parse("08-15-05");
"sonu" <kr*******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... Try this.. theDate =System.DateTime.Parse("08-15-05");
That seems to work.
But if I now have a string set to a date, such as
sDate = "09/15/05"
or
s1Date = "15-23-2005"
How would I compare these to "theDate" that we set above?
Thanks,
Tom
tshad <ts**********@ftsolutions.com> wrote: "sonu" <kr*******@yahoo.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com... Try this.. theDate =System.DateTime.Parse("08-15-05");
That seems to work.
But if I now have a string set to a date, such as
sDate = "09/15/05" or s1Date = "15-23-2005"
How would I compare these to "theDate" that we set above?
Convert the other string to a DateTime in the same way, and compare the
two DateTimes (eg using ==).
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
You might have some problems using "15-23-2005" ...
but thats just a thought :-p
In addition to Jon,
If you compare Dates than it is easy to do it as this
if (myDate.Ticks == theOtherDate.Ticks)
I hope this helps,
Cor
Cor Ligthert [MVP] <no************@planet.nl> wrote: In addition to Jon,
If you compare Dates than it is easy to do it as this
if (myDate.Ticks == theOtherDate.Ticks)
I hope this helps,
It's easier than that - it's as easy as:
if (myDate == theOtherDate)
because == is overloaded for DateTimes.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl... In addition to Jon,
If you compare Dates than it is easy to do it as this
if (myDate.Ticks == theOtherDate.Ticks)
That's true, as well as day, month and year.
Thanks,
Tom I hope this helps,
Cor
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... tshad <ts**********@ftsolutions.com> wrote: "sonu" <kr*******@yahoo.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com... > Try this.. > theDate =System.DateTime.Parse("08-15-05"); That seems to work.
But if I now have a string set to a date, such as
sDate = "09/15/05" or s1Date = "15-23-2005"
How would I compare these to "theDate" that we set above?
Convert the other string to a DateTime in the same way, and compare the two DateTimes (eg using ==).
That would make sense, as the conversion would check to make sure it is a
valid date as well.
Thanks,
Tom -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Jon, It's easier than that - it's as easy as:
if (myDate == theOtherDate)
because == is overloaded for DateTimes.
You are right, I obviously are mixing some things up.
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gleep |
last post by:
Hey Guys,
I've got a table called Outcomes. With 3 columns and 15 rows
1st col 2nd col 3rdcol
outcome date price
There are 15 rows...
|
by: Richard Hollenbeck |
last post by:
I'm trying to write some code that will convert any of the most popular
standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan
1908) and compare the first with the second and...
|
by: Stephen |
last post by:
Is there any way of using a compare validator to compare a textbox to see if
the date is greater than or equal to todays date. I want to set the
ValueToCompare property to now(). It doesn't seem...
|
by: jty202 |
last post by:
I have string that contains a date in this format (14-Jan-05). I want to
store in date object if theres one and access each part of the date (month,
year, dates, day of week).
Specifically I...
|
by: James P. |
last post by:
Hello there,
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the...
|
by: blini |
last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need
to convert and to compare if "09/06/2006 14:20" is lesser or equal that
the current date. Everything in Javascript.
|
by: Budd |
last post by:
Hi everyone
i got a problem on date, it is...
1, i get the date from calendar component
2, compare today and selected date is equal (compare method)
3 count the number of day between this...
|
by: Assimalyst |
last post by:
Hi,
I have a working script that converts a dd/mm/yyyy text box date entry
to yyyy/mm/dd and compares it to the current date, giving an error
through an asp.net custom validator, it is as...
|
by: vrparekh |
last post by:
in my webapplication,user pick date in dd/mm/yy format,
and i want to compare that date with another date using compare validator but
compare validator compare the dates using mm/dd/yy format.
...
|
by: deepikashalini |
last post by:
hi,
Im storing Issue date in database.
Issuedate stored as varchar.
and then compare to Passing string date('03/06/2008')
what is query to compare storing varchar date to passing string...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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: 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...
| |