Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Basic question about dates

Is it possible to determine the integer value of the current date?

For example, I thought this code might help, but it doesn't:

MsgBox CInt(Date) ' Returns overflow error

I get the impression that every date in VBA is represented by
a unique integer. Is that right? If so, how do you find the
integer value for any date?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Basic question about dates

Robert Crandal wrote:

Is it possible to determine the integer value of the current date?

For example, I thought this code might help, but it doesn't:

MsgBox CInt(Date) ' Returns overflow error

I get the impression that every date in VBA is represented by
a unique integer. Is that right? If so, how do you find the
integer value for any date?


You get an overflow because CInt tries to cram whatever you pass it into a
16-bit integer, which has a max value of 32,767. Use CLng() instead.

--
- There's only one thing to do.
- Hide?
- No!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Basic question about dates

"Auric__" wrote:

You get an overflow because CInt tries to cram whatever you pass it into a
16-bit integer, which has a max value of 32,767. Use CLng() instead.


Great, that's what I was looking for!

Is there a function that does the reverse? For example, if the input is
a long number, the output will be a Date string or Date value?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Basic question about dates

"Auric__" wrote:

You get an overflow because CInt tries to cram whatever you pass it
into a
16-bit integer, which has a max value of 32,767. Use CLng()
instead.


Great, that's what I was looking for!

Is there a function that does the reverse? For example, if the
input is
a long number, the output will be a Date string or Date value?


The ImmediateWindow is your friend!

12/17/2015
?clng(date)
42355

?cdate(42355)
12/17/2015

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Basic question about dates


"Auric__" wrote:

You get an overflow because CInt tries to cram whatever you pass it into a
16-bit integer, which has a max value of 32,767. Use CLng() instead.


I assume that a long number is 32 bits? That gives up to 4,294,967,295
numbers. I'm just curious, but what is the maximum date that can
be represented by Excel? Is it 12/31/9999?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Basic question about dates

Hi Robert,

Am Tue, 22 Dec 2015 01:45:22 -0700 schrieb Robert Crandal:

I assume that a long number is 32 bits? That gives up to 4,294,967,295
numbers. I'm just curious, but what is the maximum date that can
be represented by Excel? Is it 12/31/9999?


integer numbers go from -32,768 to 32,767
long numbers go -2,147,483,648 bis 2,147,483,647

The greatest date is
12/31/9999 23:59 = 2958465.99930556


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Basic question about dates

"Claus Busch" wrote:

integer numbers go from -32,768 to 32,767
long numbers go -2,147,483,648 bis 2,147,483,647

The greatest date is
12/31/9999 23:59 = 2958465.99930556


That's what I thought. Wow! Microsoft should
have it fixed by the year 10,000 so that Office
supports bigger dates, haha.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Basic question about dates

"Claus Busch" wrote:

integer numbers go from -32,768 to 32,767
long numbers go -2,147,483,648 bis 2,147,483,647

The greatest date is
12/31/9999 23:59 = 2958465.99930556


That's what I thought. Wow! Microsoft should
have it fixed by the year 10,000 so that Office
supports bigger dates, haha.


You mean.., "assuming we're still here!"<haha

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Basic question about dates

Robert Crandal wrote:
Is it possible to determine the integer value of the current date?

For example, I thought this code might help, but it doesn't:

MsgBox CInt(Date) ' Returns overflow error

I get the impression that every date in VBA is represented by
a unique integer. Is that right? If so, how do you find the
integer value for any date?



exactly a unique double because it contains also time


debug.print cdbl(now())

if you want just a date

debug.print clng(now())



it is unique number but not exactly Julian Calendar.
Microsoft for compatibility with Lotus123 made the same mistake.
29-02-1900 does not exist but both count it.


The most tricky part if convert that number back to date. :)



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic question...sorry jen the runner Excel Worksheet Functions 11 September 18th 07 12:12 AM
VBA basic question kirkm[_6_] Excel Programming 5 December 31st 06 05:39 PM
Basic VBA Question amirstal Excel Programming 2 December 20th 06 02:39 PM
Visual Basic Getting confused with Dates Darlajane Excel Programming 2 October 15th 04 12:42 PM
BASIC VBA QUESTION MASON Excel Programming 1 December 26th 03 05:04 PM


All times are GMT +1. The time now is 08:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"