-
Date variables
Why do date variables get initialized to 12:00:00 AM automatically?
I want the date variable to somehow get initialized to something I know is
unique that I know it'll only have if I assigned it to it. The reason for
this is cause I keep checking in my program if the variable has a date to
it to see if a process ran. But, if VB automatically puts in 12:00:00 AM,
I can't do it.
Can I work around this somehow w/ out creating another variable to check
if something was done?
Thanks.
-
Re: Date variables
"sunny" <vb.@127.0.0.1> wrote in message news:3d1b7694$1@10.1.10.29
> Why do date variables get initialized to 12:00:00 AM automatically?
> I want the date variable to somehow get initialized to something I
> know is unique that I know it'll only have if I assigned it to it.
> The reason for this is cause I keep checking in my program if the
> variable has a date to it to see if a process ran. But, if VB
> automatically puts in 12:00:00 AM, I can't do it.
> Can I work around this somehow w/ out creating another variable to
> check if something was done?
A Date variable always holds a valid date/time combination. If the value is
zero (the default) then that translates to midnight on 30 Dec 1899. When
you display a date without specifying a format VB checks and if the Date
portion is zero it shows just the time portion. If the Date portion is any
other value and the time portion is zero then it just displays the date.
For other values both the date and time are displayed by default. to force
it to show it all try:
debug.print format$(mydate,"dd-mmm-yyyy hh:nn:ss")
Depending on your process you can check to see if the date is outside
whatever range is valid or you could use a Variant instead of a Date and
check for Empty or Null or some other value or you can use another variable
to hold the yes/no status and only check the date value if the process ran.
-
Re: Date variables
Hi Sunny --
> Why do date variables get initialized to 12:00:00 AM automatically?
Actually, they initialize to midnight on Saturday, December 30, 1899. That's the
*zero* point for serialdates. The history behind this is that there didn't used to
be a Data datatype -- dates were stored in Doubles. Doubles are initialized to zero,
as are other numeric types. (Why 12/30/1899 was chosen, I have no idea.)
> I want the date variable to somehow get initialized to something I know is
> unique that I know it'll only have if I assigned it to it. The reason for
> this is cause I keep checking in my program if the variable has a date to
> it to see if a process ran. But, if VB automatically puts in 12:00:00 AM,
> I can't do it.
Well, it's pretty fair odds that *if* a process ran, it either did this century or
last, not during the 19th century, huh? ;-)
> Can I work around this somehow w/ out creating another variable to check
> if something was done?
Something like this:
If Year(d) >= 1900 Then
?
Later... Karl
--
[Microsoft Basic: 1976-2001, RIP]
-
Re: Date variables
On 27 Jun 2002 13:33:24 -0800, "sunny" <vb.@127.0.0.1> wrote:
>Why do date variables get initialized to 12:00:00 AM automatically?
>I want the date variable to somehow get initialized to something I know is
>unique that I know it'll only have if I assigned it to it. The reason for
>this is cause I keep checking in my program if the variable has a date to
>it to see if a process ran. But, if VB automatically puts in 12:00:00 AM,
>I can't do it.
See the other responses here, but the key is the fact that the zero
value is a specific time *and* date. Unless the dates you're dealing
with happen to include the "zero date" you should be able to test for
this date/time to know if the data has been entered. A test for "=0"
may be what you're looking for.
Another way to do this, if you're only interested in the date part and
the zero date is a possible valid value, is to use the time part as a
flag. When the date has been entered, enter a known "nonzero" time
part like 6am (0.25).
For history, the original "date/time library" was an external linkable
library with PDS. Doubles were used to hold date/time with the whole
part being a date serial number and the fractional part being the time
(fraction of a day). Noon is 0.5 for example... 6am is 0.25, 0.00 is
midnight. If you are dealing with existing code or stored data files
you will likely find the data stored as a double. Negative values are
valid, they're just dates prior to the zero date.
All versions of Visual Basic use this method though they've added a
specific data type to hold it. Well, all versions except VB.Net use
this method. All bets are off there.
Dan
Language Stability is a *feature* I wish VB had!
(#6)
Error 51
Error 3
Error 9
....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|