473,626 Members | 3,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Errors in .NET 2.0

Here is my code:

*****

Public Property DOB() As Date
Get
Try

DOB = (msBirthMonth + "/" + msBirthDay + "/" +
msBirthYear)

Catch e As Exception

DOB = Nothing
End Try
End Get
Set(ByVal d As Date)
Try
msBirthMonth = Month(d).ToStri ng
msBirthDay = Day(d).ToString
msBirthYear = Year(d).ToStrin g
Catch ex As Exception
msBirthMonth = ""
msBirthDay = ""
msBirthYear = ""
End Try
End Set

End Property

****
values passed are:
msBirthMonth = '01'
msBirthDay = '01'
msBirthYear = '1950'

***

The error that I get is, "Conversion from String "01/01/1950" to type
date is not valid"

This code worked in .NET 1.1, now that I'm converting to .NET 2.0, this
code no longer works.

Any suggestions?

May 8 '06 #1
10 1668
Milissa,
Consider using a Date constructor instead:

| DOB = (msBirthMonth + "/" + msBirthDay + "/" +
| msBirthYear)

Return New Date(CInt(msBir thYear), CInt(msBirthMon th), CInt(msBirthDay ))

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<me**********@g mail.com> wrote in message
news:11******** *************@y 43g2000cwc.goog legroups.com...
| Here is my code:
|
| *****
|
| Public Property DOB() As Date
| Get
| Try
|
| DOB = (msBirthMonth + "/" + msBirthDay + "/" +
| msBirthYear)
|
| Catch e As Exception
|
| DOB = Nothing
| End Try
| End Get
| Set(ByVal d As Date)
| Try
| msBirthMonth = Month(d).ToStri ng
| msBirthDay = Day(d).ToString
| msBirthYear = Year(d).ToStrin g
| Catch ex As Exception
| msBirthMonth = ""
| msBirthDay = ""
| msBirthYear = ""
| End Try
| End Set
|
| End Property
|
| ****
| values passed are:
| msBirthMonth = '01'
| msBirthDay = '01'
| msBirthYear = '1950'
|
| ***
|
| The error that I get is, "Conversion from String "01/01/1950" to type
| date is not valid"
|
| This code worked in .NET 1.1, now that I'm converting to .NET 2.0, this
| code no longer works.
|
| Any suggestions?
|
May 8 '06 #2
Ok, I tried returning the new date as you suggested - no luck...
I tried DOB = new date(...) no luck...
I tried dim mydate as date - put values in there and then dob = mydate
.... no luck

Setting a date property should be easier than this... Had the issue
been the fact that the string was originally in dd/mm/yyyy format,
converting the strings to integers should have resolved any of those
problems, but yet overriding the values and hard-coding the date value
should have resolved something also, which it still errors. I have been
stepping through debug, and msBirthMonth, ...day, ...year are passing
properly.

This is not the only date function that has errored on the conversion
to .NET 2.0 - ALL dates in the application are not returning
appropriate values. Instead all I get is #12:00:00 AM# for the dob
values in my watch.

These are simply drop down boxes on an ASPX page that stores their
values into birthmonth, birthyear and birthday. Those are then
converted by public properties to strings as msbirthmonth, msbirthday,
msbirthyear - then those string values are put in the date...

May 9 '06 #3
Liz

<me**********@g mail.com> wrote in message
news:11******** *************@y 43g2000cwc.goog legroups.com...
Here is my code:

*****

Public Property DOB() As Date
Get
Try

DOB = (msBirthMonth + "/" + msBirthDay + "/" +
msBirthYear)

Catch e As Exception

DOB = Nothing
End Try
End Get
Set(ByVal d As Date)
Try
msBirthMonth = Month(d).ToStri ng
msBirthDay = Day(d).ToString
msBirthYear = Year(d).ToStrin g
Catch ex As Exception
msBirthMonth = ""
msBirthDay = ""
msBirthYear = ""
End Try
End Set

End Property

for one thing, DOB is declared as Date and your GET returns a string value
....
****
values passed are:
msBirthMonth = '01'
msBirthDay = '01'
msBirthYear = '1950'
values passed to what ? how ? your SET wants a single Date argument ...
you're passing it three strings ?

***

The error that I get is, "Conversion from String "01/01/1950" to type
date is not valid"

This code worked in .NET 1.1, now that I'm converting to .NET 2.0, this
code no longer works.


you were probably doing implicit conversions with Option Strict Off ... I
can't really follow your code or your intent; turning Option Strict OFF
might do the trick here but I would re-think the whole thing and get all the
data typing and logic straight

it looks like you want to pass a date value in and then return a string
value .... but then it doesn't .... it's confused; and the Try ... Catch in
your GET is suspect ... what is it you're doing there ? why not just control
the input ? and the purpose of setting DOB = Nothing is what ?


May 10 '06 #4
I'm fixing mumbled jumbled contractor code while converting from .NET
1.1 to .NET 2.0.

This was code that they origionally had a contractor do and on
conversion it all died! So as far as the why's, what for's... I have no
idea why they did half of anything to begin with.
values passed to what ? how ? your SET wants a single Date argument ...
you're passing it three strings ?
They passed string values from textboxes into variables, it's stored in
variables under applicant.dob.m onth, applicant.dob.d ay,
applicant.dob.y ear - and then they passed it into the msBirthMonth,
msBirthDay, msBirthYear ...and then changed to BirthMonth, BirthYear,
BirthDay later... then converted into a date, but it still uses string
values further in the application, but the end result is that it's
stored as a date in SQLServer... o.O
you were probably doing implicit conversions with Option Strict Off ... I
can't really follow your code or your intent; turning Option Strict OFF
might do the trick here but I would re-think the whole thing and get all the
data typing and logic straight
Thanks, I'll try that.
it looks like you want to pass a date value in and then return a string
value .... but then it doesn't .... it's confused; and the Try ... Catch in
your GET is suspect ... what is it you're doing there ? why not just control
the input ? and the purpose of setting DOB = Nothing is what ?


I can't even answer why they did that. Just that I have to fix all this
code. :|

May 10 '06 #5
Melissa Nava wrote:
I'm fixing mumbled jumbled contractor code while converting from .NET
1.1 to .NET 2.0.

This was code that they origionally had a contractor do and on
conversion it all died! So as far as the why's, what for's... I have no
idea why they did half of anything to begin with.


The problem isn't really the conversion from 1.1 to 2.0, but the fact
that the code is badly written to start with. (Apologies to the original
author for being so frank...)

It uses an implicit conversion from a string to date, which means that
it uses the current culture to decide how to parse the string. Unless
the application specifically sets the culture, the code is very
sensetive to changes in the environment.

For parsing the strings into a date you could use something like:

Dim m as Integer, d as Integer, y as Integer

If Integer.TryPars e(msBirthYear, y) and Integer.TryPars e(msBirthMonth,
m) and Integer.TryPars e(msBirthDay, d) Then
DOB = New Date(y, m, d)
Else
DOB = Nothing
End If

[With reservations for errors - I don't usually program VB]
values passed to what ? how ? your SET wants a single Date argument ...
you're passing it three strings ?


They passed string values from textboxes into variables, it's stored in
variables under applicant.dob.m onth, applicant.dob.d ay,
applicant.dob.y ear - and then they passed it into the msBirthMonth,
msBirthDay, msBirthYear ...and then changed to BirthMonth, BirthYear,
BirthDay later... then converted into a date, but it still uses string
values further in the application, but the end result is that it's
stored as a date in SQLServer... o.O


As it is a date, it should really be handled as a date throughout the
application, not a bunch of strings.
you were probably doing implicit conversions with Option Strict Off ... I
can't really follow your code or your intent; turning Option Strict OFF
might do the trick here but I would re-think the whole thing and get all the
data typing and logic straight


Thanks, I'll try that.
it looks like you want to pass a date value in and then return a string
value .... but then it doesn't .... it's confused; and the Try ... Catch in
your GET is suspect ... what is it you're doing there ? why not just control
the input ? and the purpose of setting DOB = Nothing is what ?


I can't even answer why they did that. Just that I have to fix all this
code. :|

May 10 '06 #6
Melissa,
| Ok, I tried returning the new date as you suggested - no luck...
| I tried DOB = new date(...) no luck...
By "no luck" what do you mean, what is the specific error you are getting.
Where specifically are you seeing a problem & what specifically is the
problem. Are you certain (absolutely certain) that this routine is failing &
not another routine?
My code assumes that msBirthMonth, msBirthDay, and msBirthYear are strings
with numbers in them and are in the respective ranges. Göran's code will
ensure they are integers.

For example:
Dim msBirthMonth As String = "01"
Dim msBirthDay As String = "01"
Dim msBirthYear As String = "1950"

Dim aDate As Date = New Date(CInt(msBir thYear), CInt(msBirthMon th),
CInt(msBirthDay ))

Sets the aDate variable to #1/1/1950#.

Moving from .NET 1.1 to .NET 2.0 would not (should not) affect your date
logic.
| Setting a date property should be easier than this...
It is!

Private m_dob

Public Property DOB() As Date
Get
Return m_dob
End Get
Set(ByVal value As Date)
m_dob = value
End Set

End Property

Is all the code for DOB really needs.

It really depends on how msBirthMonth, ...day, ...year are being used
elsewhere if they are actually needed or not...
| I have been
| stepping through debug, and msBirthMonth, ...day, ...year are passing
| properly.
Are you getting tripped up in PostBack? Remember a web page's object get
recreated each time they post back, if you set the DOB property when the
page is initially displayed, then attempt to use DOB in the post back (in
response to a button click for example) then msBirthMonth, ...day, ...year
(ergo DOB) will have reverted to blanks...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Melissa Nava" <me**********@g mail.com> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
| Ok, I tried returning the new date as you suggested - no luck...
| I tried DOB = new date(...) no luck...
| I tried dim mydate as date - put values in there and then dob = mydate
| ... no luck
|
| Setting a date property should be easier than this... Had the issue
| been the fact that the string was originally in dd/mm/yyyy format,
| converting the strings to integers should have resolved any of those
| problems, but yet overriding the values and hard-coding the date value
| should have resolved something also, which it still errors. I have been
| stepping through debug, and msBirthMonth, ...day, ...year are passing
| properly.
|
| This is not the only date function that has errored on the conversion
| to .NET 2.0 - ALL dates in the application are not returning
| appropriate values. Instead all I get is #12:00:00 AM# for the dob
| values in my watch.
|
| These are simply drop down boxes on an ASPX page that stores their
| values into birthmonth, birthyear and birthday. Those are then
| converted by public properties to strings as msbirthmonth, msbirthday,
| msbirthyear - then those string values are put in the date...
|
May 10 '06 #7
Liz

"Melissa Nava" <me**********@g mail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
I'm fixing mumbled jumbled contractor code while converting from .NET
1.1 to .NET 2.0.


oh. been there and done that ... I usually start over; it's faster and
you get better code ... provided that your "powers that be" can bear the
thought of throwing away the garbage they paid for ....


May 10 '06 #8
By "no luck" what do you mean, what is the specific error you are getting.
Where specifically are you seeing a problem & what specifically is the
problem. Are you certain (absolutely certain) that this routine is failing &
not another routine?
By "no luck" I mean that no matter how I try to set the DOB as a date,
I get the "Conversion from String "01/01/1950" to type date is not
valid" exception error thrown in the get statement.
| Public Property DOB() As Date
| Get
| Try
| DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear)
| Catch e As Exception
| DOB = Nothing
| End Try
| End Get My code assumes that msBirthMonth, msBirthDay, and msBirthYear are strings
with numbers in them and are in the respective ranges. Göran's code will
ensure they are integers. For example:
Dim msBirthMonth As String = "01"
Dim msBirthDay As String = "01"
Dim msBirthYear As String = "1950"
Dim aDate As Date = New Date(CInt(msBir thYear), CInt(msBirthMon th),
CInt(msBirthDay ))
Sets the aDate variable to #1/1/1950#.
In theory yes, this should work and if I put it in other areas of the
project, it works and returns an appropriate value. Inside of my
variableobject code within my Get/Set statement, this same code (that
works elsewhere) fails with an exception.
It really depends on how msBirthMonth, ...day, ...year are being used
elsewhere if they are actually needed or not...
They are used throughout the application for various purposes,
determining the age of an applicant to see if they are filing the
appropriate application, adding it to the database, checking for
various things such as if an applicant states that they were born in
1999, but had an absence during 1998, it will let them know that they
cannot report absences for a time before they were born...etc. So yes,
the DOB and different day, month, year values are used multiple times
throughout the application.
Are you getting tripped up in PostBack? Remember a web page's object get
recreated each time they post back, if you set the DOB property when the
page is initially displayed, then attempt to use DOB in the post back (in
response to a button click for example) then msBirthMonth, ...day, ...year
(ergo DOB) will have reverted to blanks...


I wish it was that easy... For DOB to revert to blank it would have to
have a value at some point. At this point I cannot get it to hold a
value at all. Stepping through debugger, it never even gets a value,
the values in the msBirthday, msBirthYear and msBirthMonth will hold
appropriate values. I have even tried using other values as the
application also holds birthdate information in regular Birthday,
BirthMonth and BirthYear... I have found a way to bypass the DOB
property, which will get me past the applications validations, error
handling, and let me continue through the application, but at the end
of the application since the DOB VO property is nothing it will error
on database save. (So If I don't fix it now, I can bypass this problem,
but eventually I have to figure it out. *bleh*)

I have encorporated the help of a Systems Programmer V here at my work
and this has him confused as well... Especially due to the fact that
the code is working if it is outside of the variable object.

Of course, thank you for your help, so far we have tried using
everyone's suggestions to no avail, but we definately know a dozen ways
that this won't work now! :)

May 10 '06 #9
Melissa,
Can you post or send me a "Short but Complete" sample that demonstrates the
problem?

For "Short but Complete" see:
http://www.yoda.arachsys.com/csharp/complete.html
If you can get it down to 15 to 20 lines that consistently cause the problem
feel free to post them here. If you have substantially more you may email
directly, this email address is not mangled...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Melissa Nava" <me**********@g mail.com> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
By "no luck" what do you mean, what is the specific error you are getting.
Where specifically are you seeing a problem & what specifically is the
problem. Are you certain (absolutely certain) that this routine is failing
&
not another routine?
By "no luck" I mean that no matter how I try to set the DOB as a date,
I get the "Conversion from String "01/01/1950" to type date is not
valid" exception error thrown in the get statement.
| Public Property DOB() As Date
| Get
| Try
| DOB = (msBirthMonth + "/" + msBirthDay + "/" +
msBirthYear)
| Catch e As Exception
| DOB = Nothing
| End Try
| End Get My code assumes that msBirthMonth, msBirthDay, and msBirthYear are strings
with numbers in them and are in the respective ranges. Göran's code will
ensure they are integers. For example:
Dim msBirthMonth As String = "01"
Dim msBirthDay As String = "01"
Dim msBirthYear As String = "1950"
Dim aDate As Date = New Date(CInt(msBir thYear),
CInt(msBirthMon th),
CInt(msBirthDay ))
Sets the aDate variable to #1/1/1950#.
In theory yes, this should work and if I put it in other areas of the
project, it works and returns an appropriate value. Inside of my
variableobject code within my Get/Set statement, this same code (that
works elsewhere) fails with an exception.
It really depends on how msBirthMonth, ...day, ...year are being used
elsewhere if they are actually needed or not...
They are used throughout the application for various purposes,
determining the age of an applicant to see if they are filing the
appropriate application, adding it to the database, checking for
various things such as if an applicant states that they were born in
1999, but had an absence during 1998, it will let them know that they
cannot report absences for a time before they were born...etc. So yes,
the DOB and different day, month, year values are used multiple times
throughout the application.
Are you getting tripped up in PostBack? Remember a web page's object get
recreated each time they post back, if you set the DOB property when the
page is initially displayed, then attempt to use DOB in the post back (in
response to a button click for example) then msBirthMonth, ...day, ...year
(ergo DOB) will have reverted to blanks...


I wish it was that easy... For DOB to revert to blank it would have to
have a value at some point. At this point I cannot get it to hold a
value at all. Stepping through debugger, it never even gets a value,
the values in the msBirthday, msBirthYear and msBirthMonth will hold
appropriate values. I have even tried using other values as the
application also holds birthdate information in regular Birthday,
BirthMonth and BirthYear... I have found a way to bypass the DOB
property, which will get me past the applications validations, error
handling, and let me continue through the application, but at the end
of the application since the DOB VO property is nothing it will error
on database save. (So If I don't fix it now, I can bypass this problem,
but eventually I have to figure it out. *bleh*)

I have encorporated the help of a Systems Programmer V here at my work
and this has him confused as well... Especially due to the fact that
the code is working if it is outside of the variable object.

Of course, thank you for your help, so far we have tried using
everyone's suggestions to no avail, but we definately know a dozen ways
that this won't work now! :)
May 10 '06 #10

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

Similar topics

4
5364
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 calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
26
4233
by: sgershon | last post by:
Hi. I know this is should be a simple question. I know server-side web-programming, and never needed to use client-side scripting... until now :) I have done so far a little number of scripts that work well. But there are two that I am having special difficulties with: 1)
6
4840
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is selected and submitted. Thanks in advance for any help.
3
1857
by: arthur-e | last post by:
A new Machine was set up by our IS department - it came with Office Pro 2003. Access97, Word97 and Excel 97 were added. I'm trying to update an Access 97database to 2003 but get weird compiling errors - Date, Format and Left give errors. I've registered the missing (or those ocx's) that were indicated as missing- iincluding - mscomct2.ocx - and the date picker showed up but
17
71392
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
10
3265
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a procedure to do this in VB.NET (2005 Express Edition). But I always get the message that the Jet database engine does not recognize the syntax (of the Date function I assume). I've also tried Now() and it works but only by itself. I seem to add or
2
8183
by: Claes Wedin | last post by:
My customer needs a DateTimePicker in VS2005 C# that can show emty date values (blank/space/null). I need a control that: 1. Can show a blank value 2. Detete a date when hitting the delete and/or back key 3. Allowse the user to enter yyyy-MM-dd date format manually 4. When tabbed into the field behaves juast like a textbox
3
3434
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the current date and time expressed in minutes? Once I have this number I can add the number of minutes purchased to the current date/time to get the expiration date.
2
2347
by: samvb | last post by:
Hi, I have just finished a program that uses ms access and depends on system date to do certain things. just when i was testing it, a friend suggested that i change system date to see how it reacts. And it totally failed if the system date changes. I have written a small module that can save me from this errors upon the user's request i.e. the user clicks a button to reset the date using my program. during the reseting process, i fix any date...
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4092
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.