Day, Weekday, and Year functions are not working but Month is?

Here’s my code:

Sub Test

Dim myDate As Date
Dim myDay As Integer
Dim myMonth As Integer
Dim myYear As Integer
Dim myWeekday As Integer

myDate = DateSerial(2017, 8, 15)
myDay = Day(myDate)			'Returns 0
myMonth = Month(myDate)		'Working
myYear = Year(myDate)		'Returns 0
myWeekday = WeekDay(myDate)	'Returns 0

msgBox myWeekday & ", " & myDay & ", " & myMonth & ", " & myYear & " = " & myDate

End Sub

I’ve read what I think are the latest guides. I’ve scoured the Interweb for my answer. Everything tells me that this should work. “Month” works fine, but the rest do not. What am I missing?



Not sure what is happening on your end but works as expected here:

image description

Only changed Sub name because already had one with Test.

What is your operating system & LO version?

Works for me too, on Win 10 64 bits, latest LibO 32 bits.

That’s odd.

OS: Ubuntu 16.04



Interesting development:

If I put the code under “My Macros and Dialogs,” or if I put it under another document, or even in a different module in the same document it works. It does not work module I want it to.

I found my problem.

I had named a var “year” in another Sub.

Thanks for your responses

If someone could mark this as the correct answer. I’d appreciate it. Thanks.