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

DateTime

Hello,

I defined a DateTime variable:

Dim dt As New DateTime

How can I check if it is empty?

Basically I want to check if it was given to it a DateTime value or
not.

Thanks,

Miguel

Feb 23 '07 #1
5 2836
You can't. DataTime is a ValueType..it's stored on the stack and always has
a default value (like an int).

a hack solution is to assign it a value that'll never get used:

dim dt as datetime = datetime.MinValue

but that's a hack.

In 2.0, you can use a nullable type...

dim dt as Nullable(Of DateTime)

which you can then compare against nothing and do other stuff...still not
great, but the best solution.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"shapper" <md*****@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
Hello,

I defined a DateTime variable:

Dim dt As New DateTime

How can I check if it is empty?

Basically I want to check if it was given to it a DateTime value or
not.

Thanks,

Miguel
Feb 23 '07 #2
"shapper" <md*****@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
I defined a DateTime variable:

Dim dt As New DateTime

How can I check if it is empty?

Basically I want to check if it was given to it a DateTime value or
not.
You can't, at least, not 100% reliably. When a DateTime variable is
instantiated, its default value is DateTime.MinValue, not null. You could
check whether dt = DateTime.MinValue, but it will never be null (or empty)
because it is a value type.

..NET 2 introduced the concept of nullable datatypes e.g. DateTime? as well
as DateTime etc. However, when a DateTime? variable is instantiated, it also
has a default value of DateTime.MinValue - you can, though explicitly set a
DateTime? variable to null, which you can't do with a DateTime variable...
Feb 23 '07 #3
"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenetwr ote
in message news:C5**********************************@microsof t.com...
In 2.0, you can use a nullable type...

dim dt as Nullable(Of DateTime)
Yes, but you will have to explicitly set it to Nothing first, won't you...?
Feb 23 '07 #4
not in C#..maybe vb.net..dunno.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenet >
wrote in message
news:C5**********************************@microsof t.com...
>In 2.0, you can use a nullable type...

dim dt as Nullable(Of DateTime)

Yes, but you will have to explicitly set it to Nothing first, won't
you...?
Feb 23 '07 #5
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenet >
wrote in message
news:C5**********************************@microso ft.com...
>>In 2.0, you can use a nullable type...

dim dt as Nullable(Of DateTime)

Yes, but you will have to explicitly set it to Nothing first, won't
you...?
"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenetwr ote
in message news:4A**********************************@microsof t.com...
not in C#..maybe vb.net..dunno.
Oh sure - not a problem at all in C#...

DateTime? dt = null;
Feb 24 '07 #6

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

Similar topics

4
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
3
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
5
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
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...
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
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,...
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
isladogs
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 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.