Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using zero in DateSerial 1

Status
Not open for further replies.

Madawc

Programmer
Sep 5, 2002
7,628
GB
Checking someone else's Crystal report, I found that they had got the last day of a month as follows:
Code:
DateSerial (Year({MYOWN.date}), Month({MYOWN.date})+1, 0)

This did work, at least in Crystal 10. Is it valid? Or should one always use some version of the standard method,
Code:
DateSerial (Year({MYOWN.date}), Month({MYOWN.date})+1, 1) -1


[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
It works in Xi r1 and r2.
I've usually done it the second way you have listed. This is a nice short cut.

Thank you
 
In case anyone cares, this also works in Excel.
=DATE(2006,12,0) yields 11/30/06
 
I haven't tested this in multiple situations, but it seems to work, and is simpler than the usual method. Thanks (*).

-LB
 
Interesting...

I would caution against using such workarounds, things may change in the future, and the difference in the amount of code written is insignificant.

Sometimes being clever, ain't.

I did play around with this, and you can cheat quite a few things, note that you can use negative numbers also.

-k
 
Thanks for the replies. I agree with synapsevampire - even if it works now, it could work differently in a future version.

It might simply fail - I've had that in another language, dodges that work but get rejected in updated versions. But there is worse, if your report is being written for someone else to use. You could imagine it producing a subtle error in some important figures that will cause a lot of worry before it's found that your short-cut was to blame.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top