473,398 Members | 2,165 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,398 software developers and data experts.

convert Date type property to String

how are people dealing with the situation where a function accepts a String
representation of a date ... but a control on the page or form returns a
Date value ...

strangely, these Date values can be Nothing but not in the sense of a object
reference to Nothing ...

rather, you supposedly can use an equality comparison

MyControl.Date = Nothing
Nov 20 '05 #1
6 1948
to convert DateTime to a string

Dim myStringDateTime As String = MyDateTime.ToString()
Regards - OHM

John A Grandy wrote:
how are people dealing with the situation where a function accepts a
String representation of a date ... but a control on the page or form
returns a Date value ...

strangely, these Date values can be Nothing but not in the sense of a
object reference to Nothing ...

rather, you supposedly can use an equality comparison

MyControl.Date = Nothing


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #2
* "John A Grandy" <johnagrandy-at-yahoo-dot-com> scripsit:
how are people dealing with the situation where a function accepts a String
representation of a date ... but a control on the page or form returns a
Date value ...
Have a look at the 'DateTime''s 'ToString' method, which can be used to
convert the date to a string.
strangely, these Date values can be Nothing but not in the sense of a object
reference to Nothing ...


'DateTime' is a value type, assigning 'Nothing' will assign the "default
value" of the datatype for value types.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Cor
Hi John,

I have tried to make this morning an example about this subject, I am not
sure if all is right, so I ask OHM, Armin, HKW or Jay B if they will check
it?

Cor

\\\
Public Module mymodule
Public Sub main()
Dim a As Date = Nothing
If a = Nothing Then
MessageBox.Show("Empty date value")
End If
Dim b As String
If b Is Nothing Then
MessageBox.Show("String with no pointer")
End If
b = ""
If b = Nothing Then
MessageBox.Show("String with 0 characters")
End If
Dim c As mydate
If c Is Nothing Then
MessageBox.Show("Object with no reference")
End If
c = New mydate("31/31/03") 'false to create error
If c.date Is Nothing Then
MessageBox.Show("Object with no property date")
End If
c = New mydate("")
If Not c Is Nothing Then
If c.date Is Nothing Then
MessageBox.Show("Existing object with an empty property
date")
End If
End If
Dim d As Object
d = New Date
If d Is Nothing Then
MessageBox.Show("Empty object date")
End If
d = New Date(Nothing)
If DirectCast(d, Date) = Nothing Then
MessageBox.Show("Empty boxed date")
End If
End Sub
End Module
Public Class mydate
Private mydate As Date
Public Sub New(ByVal dat As String)
If dat <> "" Then
Try
mydate = Convert.ToDateTime(dat)
Catch
End Try
Else
mydate = Nothing
End If
End Sub
Public ReadOnly Property [date]() As mydate
Get
mydate = mydate
End Get
End Property
End Class

///

Nov 20 '05 #4
"Cor" <no*@non.com> schrieb

Hi Cor,
I have tried to make this morning an example about this subject, I am
not sure if all is right, so I ask OHM, Armin, HKW or Jay B if they
will check it?
As you've asked for: :-)
I *never* use Nothing with value types. To me, Nothing means "no reference".
I am not really sure what your code aims at. If I understand John correctly,
he wants to convert between Date and String. If the thing is to set a Date
to Nothing or a Date value, I'd write a WrappedDate class (see below).
Public Class mydate
Private mydate As Date
Public Sub New(ByVal dat As String)
If dat <> "" Then
Try
mydate = Convert.ToDateTime(dat)
Catch
End Try
Else
mydate = Nothing
End If
End Sub
Public ReadOnly Property [date]() As mydate
Get
mydate = mydate
Tiny correction:

[date] = mydate
or
return mydate
End Get
End Property
End Class


class WrappedDate
public Value as date
public sub new(byval Value as date)
me.value = value
end sub
end class

Just my 2 Euro-c.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Cor
Hi Armin,

My aim is to have a sample ready for all those "nothing" situations.
return mydate


I am in deep shame

I always mix the get and the set and have to check it, maybe is the reason
that it goes wrong (I have used it so much but still the same problem).

Now I could change the sampel back to what I wanted, when you have additions
please tell it.
I put the sample as corrected beneath the other, so the others see it also.

Thanx

Cor
Nov 20 '05 #6
Cor
Corrected while there was a stupidity in that Armin saw.

\\\
Public Module mymodule
Public Sub main()
Dim a As Date = Nothing
If a = Nothing Then
MessageBox.Show("Empty date value")
End If
Dim b As String
If b Is Nothing Then
MessageBox.Show("String with no pointer")
End If
b = ""
If b = Nothing Then
MessageBox.Show("String with 0 characters")
End If
Dim c As mydate
If c Is Nothing Then
MessageBox.Show("Object with no reference")
End If
c = New mydate("")
If c.date = Nothing Then
MessageBox.Show("Existing object with an empty property date")
End If
Dim d As Object
If d Is Nothing Then
MessageBox.Show("Not Existing object")
End If
d = New Date
If Not d Is Nothing Then
MessageBox.Show("Existing object date")
End If
d = New Date(Nothing)
If DirectCast(d, Date) = Nothing Then
MessageBox.Show("Empty boxed date")
End If
End Sub
End Module
Public Class mydate
Private mydat As Date
Public Sub New(ByVal dat As String)
Try
mydat = Convert.ToDateTime(dat)
Catch
mydat = Nothing
End Try
End Sub
Public ReadOnly Property [date]() As Date
Get
Return mydat
End Get
End Property
End Class
///
Nov 20 '05 #7

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

Similar topics

1
by: Loi Tan Vo | last post by:
Hi, I have a text file that contains a date column. The text file will be imported to database in SQL 2000 server. After to be imported, I want to convert the date column to date type. For...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
7
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...
1
by: Tan | last post by:
Hello I have a property date in the object data sourse which bind to Detailview, when this date property is null , it will display the date 01/01/0001, how can I convert it to empty string or...
5
by: Ray | last post by:
I have a table with some audit date and time columns. Problem is the developer who stored the data left them as DECIMAL type instead of DATE and TIME. Is there a way I can convert the DECIMAL type...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
1
by: raghu1 | last post by:
How to convert a given date to its equvalent ticks.: string d="5/15/2006 12:10:44 PM"; // string 2 date ... dt=Convert.ToDateTime(d); // Date 2 ticks ... dt2ticks=dt.Ticks; string ticks =...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
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
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...
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.