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

Why is working with dates so frustrating in excel?

I have this code snippet:


dim sdate as date
sdate="01/01/1901"
stdate=right(sdate,4) & mid(sdate,4,2) & left(sdate,2)

In excel2002, stdate evalutes correctly to 19010101
but in excel 2003 I get an error at the stdate line because sdate at
this point is 1/01/1901.

What do I have to do to get consistency?

The point is to read in a date via a form in the format dd/mm/yyyy but
if no date is read in, set sdate to 01/01/1901. Then I want stdate to be
in the format yyyymmdd.

Is there another way to do this that will work across all versions of excel?

Thanks
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default excel and dates

Try this:

Dim sdate As String

That way Excel won't try to force its funky date rules on the variable.

Mike F
"inquirer" wrote in message
...
Why is working with dates so frustrating in excel?

I have this code snippet:


dim sdate as date
sdate="01/01/1901"
stdate=right(sdate,4) & mid(sdate,4,2) & left(sdate,2)

In excel2002, stdate evalutes correctly to 19010101
but in excel 2003 I get an error at the stdate line because sdate at this
point is 1/01/1901.

What do I have to do to get consistency?

The point is to read in a date via a form in the format dd/mm/yyyy but if
no date is read in, set sdate to 01/01/1901. Then I want stdate to be in
the format yyyymmdd.

Is there another way to do this that will work across all versions of
excel?

Thanks
Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default excel and dates

On Wed, 17 Aug 2005 09:13:13 +1000, inquirer wrote:

Why is working with dates so frustrating in excel?

I have this code snippet:


dim sdate as date
sdate="01/01/1901"
stdate=right(sdate,4) & mid(sdate,4,2) & left(sdate,2)

In excel2002, stdate evalutes correctly to 19010101
but in excel 2003 I get an error at the stdate line because sdate at
this point is 1/01/1901.

What do I have to do to get consistency?

The point is to read in a date via a form in the format dd/mm/yyyy but
if no date is read in, set sdate to 01/01/1901. Then I want stdate to be
in the format yyyymmdd.

Is there another way to do this that will work across all versions of excel?

Thanks
Chris


Well, sdate is a date; if you want a string representation in stdate you could
use the FORMAT function:

Dim sdate As Date
Dim stdate As String

sdate = "01/01/1901"
stdate = Format(sdate, "yyyymmdd")


--ron
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
Linking computer dates (time) to spreadsheet dates that have formu bigisle Excel Worksheet Functions 3 January 3rd 10 08:05 PM
Excel not recognizing dates as dates lawson Excel Discussion (Misc queries) 1 June 26th 07 04:39 PM
Toggle a range of Julian dates to Gregorian Dates and Back PSKelligan Excel Programming 4 May 8th 07 05:51 AM
How do I get the dates on an excel chart to stay as dates instead. Rani Charts and Charting in Excel 1 September 20th 05 05:56 PM
Charting data against dates where dates are not at fixed intervals PK Charts and Charting in Excel 4 June 16th 05 05:08 AM


All times are GMT +1. The time now is 02:38 PM.

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

About Us

"It's about Microsoft Excel"