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

Work with date

How do I check if a date variable is empty?

I mean, if I declare a variable like this

dim d as Date

how do I know if any date was assigned to d?

example,
d = now

I am currently using

if d.tostring = "01/01/0001 12:00:00 AM" then
'its empty
end if

but if the UICulture is different from en-US, it won't work....

is there any good way to check this?

Thanks,
Bruno

Nov 21 '05 #1
4 1213
"Bruno" <no@no.com> schrieb:
How do I check if a date variable is empty?

I mean, if I declare a variable like this

dim d as Date

how do I know if any date was assigned to d?


\\\
If d = Nothing Then
...
Else
...
End If
///

'Date' is a value type and this cannot be 'Nothing' (a 'NULL' reference).
The 'SqlDateTime' data type can deal with 'NULL' values.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

You can check the number of ticks that the date represents, as this is not
dependant on the location. So...

if d.Ticks = 0 then
'its empty
end if

Dan

"Bruno" wrote:
How do I check if a date variable is empty?

I mean, if I declare a variable like this

dim d as Date

how do I know if any date was assigned to d?

example,
d = now

I am currently using

if d.tostring = "01/01/0001 12:00:00 AM" then
'its empty
end if

but if the UICulture is different from en-US, it won't work....

is there any good way to check this?

Thanks,
Bruno

Nov 21 '05 #3
Just to make things clear, the correct way to type a date literal is with ##:
if d = #1/1/1 12:00 AM# then - this will be invulnerable to different uicultures, since it converts the compared value to an actual date object at compile time.

that said, you could also just do:
If d = date.MinValue then...

Alex
MS VBQA

--------------------
From: "Bruno" <no@no.com>
Subject: Work with date
Date: Mon, 21 Feb 2005 18:26:02 -0300
Lines: 26
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <uW*************@TK2MSFTNGP15.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 201-13-119-243.dsl.telesp.net.br 201.13.119.243
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:261348
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

How do I check if a date variable is empty?

I mean, if I declare a variable like this

dim d as Date

how do I know if any date was assigned to d?

example,
d = now

I am currently using

if d.tostring = "01/01/0001 12:00:00 AM" then
'its empty
end if

but if the UICulture is different from en-US, it won't work....

is there any good way to check this?

Thanks,
Bruno

Nov 21 '05 #4
Bruno,

I don't know from which country you are, however when that is not the US or
English Canada.

Dont use date literals. They can be confusing for programmers who have to
maintain your program.

Just use the constructor from the datetime which is in the international
standard.

Dim mydate as datetime = new date(year,month,day,hour,minute,second)
or
Dim mydate as datetime = new date() 'what is the same as
Dim mydate as datetime = nothing

Be aware that the ticks from a databaseserver datetime can (mostly) start on
another date than the internal datetime.

I hope this helps,

Cor
Nov 21 '05 #5

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

Similar topics

4
by: Jeff | last post by:
Hello, I wrote a script that loops through a list of addresses and does stuff with those addresses, and while it is working there isn't anything to see. In order to be able to see progress...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
11
by: Axel Dahmen | last post by:
Hi, I'm working in a team developing an international website. When I set the page's CultureInfo to Hungarian (hu-HU) then the RangeValidator doesn't seem to be able to parse a TextBox's date...
0
by: Steve | last post by:
To begin, I'm using Adobe's Spry Framework for all my data in my XML page, it saves space and code on the HTML. Well, I want to make it so that certain cells are chosen and are either highlighted...
8
by: Ragbrai | last post by:
Howdy All, I have a query that is used for filtering results to be used in a combo box. The query needs to test fields from both a table and then unbound text boxes on the form that also contains...
5
by: Screaming Eagles 101 | last post by:
Hi, I'm looking for some code to find the right work shift according to a specific date and time. This one worked fine in VB6, but somewhere I do not succeed in converting it to VB2005 code.......
4
by: dougmeece | last post by:
Morning Everyone... I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
1
by: Christian Heimes | last post by:
Rick King schrieb: datetime.date is a C extension class. Subclassing of extension classes may not always work as you'd expect it. Christian
12
by: Mads Aggerholm | last post by:
Hello Sirs I hope you can give me a hint to this little problem. The thing is, I have for a lang time enjoyed the comics on www.washintonpost.com, and I allways start the day by going to their...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.