Date conversion question

Am trying to understand why is that when I have a variable MaxDate
(undeclared) and is has a value of 38697 and if I use
=TEXT(MaxDate,"mm/dd/yy") I get the correct value of 12/12/09 but if I
use function =CDATE(MaxDate) I get 12/11/2005 as an output?   Also the
format command didn't work either to convert MaxDate with the code
=format(MaxDate, "mm/dd/yy") as it also gave 12/11/2005 when the
correct output was 12/12/09.  I am trying to understand this.

Thanks,
Chet
0
Chet
2/21/2010 7:03:22 PM
excel.programming 6508 articles. 2 followers. Follow

6 Replies
481 Views

Similar Articles

[PageSpeed] 31

Assuming you are using XL2003 or lower... if you click to Tools/Options =
on the menu bar, then select the Calculation tab and uncheck the "1904 =
date system" check box, all your calculations will agree. Note, however, =
if you have other dates in your workbook, those dates will change also.

--=20
Rick (MVP - Excel)


"Chet" <chetshannon@gmail.com> wrote in message =
news:cd4ea64c-337c-41d7-b77c-fd37c9345fb3@x1g2000prb.googlegroups.com...
> Am trying to understand why is that when I have a variable MaxDate
> (undeclared) and is has a value of 38697 and if I use
> =3DTEXT(MaxDate,"mm/dd/yy") I get the correct value of 12/12/09 but if =
I
> use function =3DCDATE(MaxDate) I get 12/11/2005 as an output?   Also =
the
> format command didn't work either to convert MaxDate with the code
> =3Dformat(MaxDate, "mm/dd/yy") as it also gave 12/11/2005 when the
> correct output was 12/12/09.  I am trying to understand this.
>=20
> Thanks,
> Chet
0
Rick
2/21/2010 8:09:52 PM
Sub Chet()
Dim MaxDate As Long
MaxDate = 38697
MsgBox (Format(MaxDate, "mm/dd/yy"))
MsgBox (CDate(MaxDate))
End Sub

both display 12/11/2005 because that is the correct value.  If you desire 
12/12/2009, then start with 40159

-- 
Gary''s Student - gsnu201001


"Chet" wrote:

> Am trying to understand why is that when I have a variable MaxDate
> (undeclared) and is has a value of 38697 and if I use
> =TEXT(MaxDate,"mm/dd/yy") I get the correct value of 12/12/09 but if I
> use function =CDATE(MaxDate) I get 12/11/2005 as an output?   Also the
> format command didn't work either to convert MaxDate with the code
> =format(MaxDate, "mm/dd/yy") as it also gave 12/11/2005 when the
> correct output was 12/12/09.  I am trying to understand this.
> 
> Thanks,
> Chet
> .
> 
0
Utf
2/21/2010 8:16:01 PM
On Sun, 21 Feb 2010 11:03:22 -0800 (PST), Chet <chetshannon@gmail.com> wrote:

>Am trying to understand why is that when I have a variable MaxDate
>(undeclared) and is has a value of 38697 and if I use
>=TEXT(MaxDate,"mm/dd/yy") I get the correct value of 12/12/09 but if I
>use function =CDATE(MaxDate) I get 12/11/2005 as an output?   Also the
>format command didn't work either to convert MaxDate with the code
>=format(MaxDate, "mm/dd/yy") as it also gave 12/11/2005 when the
>correct output was 12/12/09.  I am trying to understand this.
>
>Thanks,
>Chet

It occurs because in your Excel options, you have selected to use the 1904 date
system.  When you use the TEXT command, it being a Worksheet Function, it uses
whichever date system you have set into your Excel Options.  In the 1904 date
system, "0" = 1/1/1904

However, CDATE, being a native VBA method, converts dates according to the
method in VBA, in which "Dates are stored as part of a real number. Values to
the left of the decimal represent the date; values to the right of the decimal
represent the time. Negative numbers represent dates prior to December 30,
1899."

--ron
0
Ron
2/21/2010 8:17:54 PM
Thanks to everyone on your answers..  it is very logical now!...  Chet
0
Chet
2/21/2010 8:59:53 PM
On Sun, 21 Feb 2010 15:17:54 -0500, Ron Rosenfeld
<ronrosenfeld@nospam.org> wrote:

> Negative numbers represent dates prior to December 30,
>1899."


  Would that not correctly be: December 31, 1899?
0
CellShocked
2/21/2010 10:06:54 PM
On Sun, 21 Feb 2010 14:06:54 -0800, CellShocked
<cellshocked@thecellvalueattheendofthespreadsheet.org> wrote:

>On Sun, 21 Feb 2010 15:17:54 -0500, Ron Rosenfeld
><ronrosenfeld@nospam.org> wrote:
>
>> Negative numbers represent dates prior to December 30,
>>1899."
>
>
>  Would that not correctly be: December 31, 1899?

In VBA, that would be true only if you consider zero to be a negative number. 
--ron
0
Ron
2/21/2010 10:41:46 PM
Reply:

Similar Artilces:

filter by date and action
I have a table with three columns: Name Date Action Fred Today this Fred Today this Fred Today that Wilma Today this I want to sort by name and by date, but only if 'this' was done more than once on the same day, and not if 'that' was done on the same day,They have to perform this more than once, and they cannot have performed that on the same day. If not in excel, mssql maybe? Thanks, Harry On Aug 18, 1:53=A0pm, Harry <hamac...@gmail.com> wrote: > I have a table with three co...

Calculate Years/Months Between Dates and then Average
We are using the formula =DATEDIF(A1,NOW(),"y") & "." & DATEDIF(A1,NOW(),"ym") to calculate the years and months from an employee hire date. Is there an easy way to average the years and months for a group of employees with the results of that formula? You could use: =AVERAGE(A1:A10*1) Array-entered, meaning press ctrl-shift-enter. But you could also just change your current formula to: =1*(DATEDIF(A1,NOW(),"y") & "." & DATEDIF(A1,NOW(),"ym")) Then just use: =AVERAGE(A1:A10) which is *not* array-entered. ...

Exchange 2003 Licensing question
We are a small company of only about 35 employees. We currently have Exch 5.5 and will be upgrading to Exch 2003. Unfortunately due to our large email store we will be force to get the Enterprise edition because we are just over the standard edition's 15 gb message store limit. I was under the impression that an Office 2003 Pro license includes a CAL for accessing Exchange 2003. What I am being told by a sales rep is that Office Pro does not include a CAL to access Exch 2003 therefore I have to buy a CAL for each user. Is this correct? The ironic thing is this. If I buy a CAL ...

Transaction Date VS Business Date
Our accounting department needs/wants to have all RMS SO reporting by business date opposed to transaction date. Usually these are the same unless you have sales and batches that close after midnight. For our store I would like to set 3 a.m. as the business day closing time. So when I run any type of reports I would like to get the information for a business date (range) starting at 3 a.m. till 3 a.m. the next day. I guess I could accomplish this by subtracting 3 hours from all the transaction (date and) times but I would have to do this for every single report which would be a lot of ...

Post Dated Checks
I had to prepare some post dated checks and we did not have fiscal periods set up yet to match the dates of the checks. Currently the check batches are waiting to be posted. What is the best way to handle post dated checks? If I create new fiscal years to match these dates, I will end up having 4 Open years. Is this the only way to do it? You can manage post dated checks in Microsoft Dynamics GP with the Payment Document Management module available on the Feature Pack 1 DVD image. For more info, take a look at MVP Mohammad Daoud's post on the subject at: https://communit...

ocx abd 97 to 2000 conversion
I have an Access 97 database using comdlg32.ocx which works fine. I have setup a new machine with Access 2000 on it. On opening the database in Access 2000, error message "One or more forms or reports contains an activex control that cannot be loaded - These controls will not function properly until you register them, open the forms or reports in design view and save the forms or reports". The rest of the open process proceeds without hitch. Also, if a form containing the comdlg32.ocx control is opened everything operates as normal except that if the button (which invokes ...

Remove "Date: Yesterday" or "Date: Monday" from Outlook Inbox?
Outlook mail inbox now has headers that tell you what day the the email was sent. I find this visually annoying. Each emailalready has the time and day it was sent. I don't need the daily titles in the midst of the list of emails. How do I make them go away? I think you are talking about OL 2003 & the Arrange in Groups setting. Change it in View, Arrange by, uncheck Show in Groups. "silky" wrote: > Outlook mail inbox now has headers that tell you what day the the email was > sent. I find this visually annoying. Each emailalready has the time and day >...

strange date format problem
Hi, I downloaded some data on excel using Bloomberg. One column has dates and the other has numbers. Dates appear as 01/01/1980 format which I want in Jan-80 format. I have changed the format cell properties but it still appears as 01/01/1980. I have to goto individual cell and press F2 <enter> so see the effect. Dont know why? I cant even copy paste format after that .... TIA/amag I am not sure, but is your workbook set to Auto-Recalculate? Try pushing <F9> to do a manual re-calculation, see if that changes the formats. If it does, go to Tools (on the menu bar), Options, Ca...

hello everyone.im new here and have a question.
i was having Seagate 160 gb hardisk and recently i got a new 320gb seagate hdd and put it as secondary disk. nw i have 4 drives i.r (C:,D:,F:,G:)..'C & D belongs to previous hardisk'.. 2 days back .i was on facebook and someone sent me a message.(link) and when i clicked it a file is downloaded automatically and from that time drives f: and g: are not opening correctly.maybe its due to some virus and ther's no use of scanning for viruses.i tried "norton, eset nod32, mc afee, avast ,avg.".but didnt work..................... if you try to open them directly...

Public Folder Question #3
I recently took over a new mixed-mode Exchange Org and am trying to clean up their Public Folder tree. There is one folder called IPM_SUBTREE that I am not familiar with. Can this be removed or is it some kind of system folder that needs to remain in place? It has several subfolders that were probably moved there by accident and need to be removed, but what about the IPM_SUBTREE? It doesn't have any items in it... DON"T REMOVE IT!!!!! This is the basic tree where your mail enabled public folders live. It is also bound to your public folder store. There are two parts to the ...

How to sort by name then date?
I would like to look through all the emails to a particular person. If I click on the "To" column I can see all the emails to a particular person (actually there is a problem with that which I will mention next) but they seem to be in random order. Is there a way to have them sorted by date? (i.e. by name first, then by date). Actually, sorting on the "To" column does not get all the emails sent to a given email address. Because Outlook uses the "display as" field. It will often give different "display as" names to the same email address. C...

Concatenate including a date so that the date appears as a date
When I try to join the contents of several cells, one of which is a date and time obtained from =now(), the date and time part appears as a number. How can I make it appear as a date and time? I have tried changing the cell formats - probably there is a combination that works but I haven't found it. I also tried copying the original date cell to another cell and changing the latter cell's format and concatenating using that latter cell, but still no success. Use the TEXT function. For example, =TEXT(NOW(),"mmmm d, yyyy") would give January 6, 2010 "dd...

Query Question
Please see the sql code below. What I am after is Sum of [RiskCount]. But due to the join, I get double counting and consequently wrong SUM. Is this an inherent limitaion of Sql? Can be it solved without breaking up the sql into two parts? Thanks for reading this post. CREATE TABLE #Location ( LocationID INT, RiskCount INT) CREATE TABLE #Coverage ( LocationID INT, Peril VARCHAR(10), Coverage VARCHAR(10), TSI Numeric(25,6)) INSERT INTO #Location VALUES (1,1) INSERT INTO #Location VALUES (2,1) INSERT INTO #Location VALUES (3,1) INSERT...

if statement with dates #2
I would like to have a statement like: IF(a1>0,1/1/2004) with 1/1/2004 beint a date. EXCEL is interpreting 1/1/2004 as an arithmetic statement and giving me the result of the arithemtic. I could put in the numeric offste for the date and write IF(a1>0,37987), formatting the cell as a date, but this seems awkward. What else can I do? TIA, Sanford ...

selectNodes question
Hi, I am trying to get nodes (in a VC++ application) using the method IXMLDOMElementPtr::selectNodes. This is part of my XML file: <None-Books> <Summary Books="34" TopContainer="13" Client="27"/> <AAA-1 Type="0" DockingCX="200" DockingCY="120" Title="a"/> <AAA-ar Type="0" DockingCX="138" DockingCY="154" Title="b"/> <Book-3 Type="0" DockingCX="365" DockingCY="120" Title="c"/> <AAA-4 Type="0"...

Counting Dates?
=COUNTIF(A1:A100,"<" & NOW()) This works good for specific cells. I have a similar question. How would I do the same thing given that: 1) You only have a starting date 2) Your only wanting to count work days (in this case 4 day/wk) up to NOW() Thank you for all your help. Aviator On Thu, 6 Jan 2005 12:53:03 -0800, "Aviator" <Aviator@discussions.microsoft.com> wrote: >=COUNTIF(A1:A100,"<" & NOW()) > >This works good for specific cells. I have a similar question. > >How would I do the same thing given that: >1) You only ha...

Count Unique Cells, within a date range (dates stored in separate column).
Hello All: I am attempting to create a formula that will count the number of unique cells (alpha-numeric) in an entire column (no set length, so ex: "$B:$B"). This count will be based on a date range (Between 2 dates). The dates are stored in another column (Ex: "$A:$A"). The following is an example of the cells. Dates PO_Num 1/2/2010 A123456 1/3/2010 B453453 2/2/2010 A123456 3/4/2010 C2342F3K 4/3/2010 123456 I would like to know a formula that can count the number of different PO's based on a given date range. Please help me if you...

An expression for dates from and to
I am trying to create an expression to select items from a date field falling from a certain date to a certain date. I am obviously missing something in my expression. The field name is DateComplete. How can I set up this expression to pull date from a certain date to a certain date? -- Ronnie Hi Ronnie, An example of the SQL would be: SELECT * FROM [TABLE NAME] WHERE DateComplete Between #1/1/2006# And #1/1/2007# ; On May 23, 3:52 pm, Ronnie <Ron...@discussions.microsoft.com> wrote: > I am trying to create an expression to select items from a date field falling > from a...

Returning only MAX(date) not all dates
I want to be able to list the most current date an item is checked out. As I was working through the query I used max as an aggregate function but I still can't get the simple result I want. I'd rather list the fields I have chosen and somehow select just the most current checkout date. Any help would be greatly appreciated. Here is my query: SELECT tblTerritory.TerritoryID, [TerritoryName] & " " & [TerritoryDescription] AS Description, tblTerritory.TerritoryTypeID, tblTerritoryType.TerritoryType, Max(tblTerritoryCheckout.DateCheckedOut) AS Checked...

Shared Borders Question....
Can 'Shared Borders' be .asp rather than .htm? There is a particular script I will like to run, but it can not be .htm. Thanks David No. -- Tom [Pepper] Willett Microsoft MVP - FrontPage Since 1997 --------------------------- "116" <116@discussions.microsoft.com> wrote in message news:52CEB706-E273-461F-9DD9-483EBA3C1F57@microsoft.com... : Can 'Shared Borders' be .asp rather than .htm? There is a particular script : I will like to run, but it can not be .htm. : : Thanks : David The shared border files must be .htm - left.htm, righ...

System Date
Can anyone help me on how to force the system date to a member field of "Date" type? I could not find any help on msdn that comes with visual c++. Any hint or help will be appreciated. Thanks, Behrouzk Are you just trying to get the current date. You can use CTime::GetCurrentTime() or COleDateTime::GetCurrentTime() Tom "Behrouzk" <Behrouzk@discussions.microsoft.com> wrote in message news:D8FA4B6B-73CE-4058-B50C-C9BEBAB67E68@microsoft.com... > Can anyone help me on how to force the system date to a member field of > "Date" type? I could not fi...

Webserver question
Hi all, I have a delphi program, which has to be "converted" in a visual C++ program. Delphi code follows: procedure TFormMain.POST(url: string; s: string); var IdHTTP: TIdHTTP; Request: TStringStream; Response: TStringStream; begin IdHTTP := TIdHTTP.Create(FormMain); Request := TStringStream.Create(s); Response := TStringStream.Create(''); try try IdHTTP.OnStatus := IdHTTPStatus; IdHTTP.Port := Port.Value; IdHTTP.Host := IPAddr.Text; IdHTTP.Request.ExtraHeaders.Add('Authorization: Basic '+ Base64Encode(Login.Text+':'...

Conditional Formatting
Hi, I have a spreadsheet that is for tracking work. I would like to have conditional formatting so that if the date in column E is between todays date and 4 weeks away then make it blue, if it is a date that is after 4 weeks away then make it yellow but if it is in the past make it red. Can this be done with conditional formatting or does it need vba? Also it would be nice if the whole row changes colour even if just the condition is on the date which is in column E - but if that can't be done then just the cell is fine. Thanks Assume the dates start in E2, select all dates w...

PrintDialog question
Can I bring up a printdialog or printsetupdialog and apply its settings to the device context when next printing? ...

Time and date problem
Hello I have spreadsheet cell (B1) that contains a date and time: 05/11/2003 13:45:50 I have another series of cells (A1 to A100) that contain an increment of 30 seconds: 30.00 I would like to add the seconds to the date and time putting the result in column C, I have tried to do: =B1+(A1/100000) but the answer is wrong by 4 seconds and then gets worse the further down the column I go. Can somebody show me how to add the seconds to the date please. Thanks Tom Tom, Right method, wrong divider! 86,400 secs in a day.. change your 100000 to 86400 and you're there. Nikos Y. (nyannaco ...