PC Review


Reply
Thread Tools Rate Thread

datepart question

 
 
Gary Keramidas
Guest
Posts: n/a
 
      5th Jan 2009
can someone explain what i am seeing?

this expression returns 4
DatePart("w", DateSerial(2009, 1, 1), vbMonday, vbFirstFullWeek)

the 1st is on thursday and the first monday is the 5th, which is 4 days later.

but this expression returns 6, which doesn't make sense to me. i would think it
would return 3
DatePart("w", DateSerial(2010, 1, 1), vbMonday, vbFirstFullWeek)

so, i guess i'm missing something.


--


Gary


 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      5th Jan 2009
Contrary to what the help file says, I don't think the 4th argument has any
bearing on the return value from the DatePart function when the first
argument is "w" (try all the possible arguments for the 4th argument... for
a given date and start of week, you will always get the same value). Now, as
to what the function is returning... I don't think it is doing what you seem
to think it is. With the "w" argument, it is giving you the weekday number
of the date you provide with the count starting as indicated by the 3rd
argument. So, for this...

DatePart("w", DateSerial(2009, 1, 1), vbMonday, vbFirstFullWeek)

it returns 4 because the January 1, 2009 occurs on a Thursday which is the
4th day of the week when the week starts on Monday (Monday is 1, Tuesday is
2, Wednesday is 3 and Thursday is 4). As for this...

DatePart("w", DateSerial(2010, 1, 1), vbMonday, vbFirstFullWeek)

you said it returns 6, but actually, it returns 5 and that is because
January 1, 2010 occurs on Friday and Friday is the 5th day of the week when
the week starts on a Monday.

--
Rick (MVP - Excel)


"Gary Keramidas" <GKeramidasAtMsn.com> wrote in message
news:ObV%(E-Mail Removed)...
> can someone explain what i am seeing?
>
> this expression returns 4
> DatePart("w", DateSerial(2009, 1, 1), vbMonday, vbFirstFullWeek)
>
> the 1st is on thursday and the first monday is the 5th, which is 4 days
> later.
>
> but this expression returns 6, which doesn't make sense to me. i would
> think it would return 3
> DatePart("w", DateSerial(2010, 1, 1), vbMonday, vbFirstFullWeek)
>
> so, i guess i'm missing something.
>
>
> --
>
>
> Gary
>
>


 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      5th Jan 2009
thanks, rick. i mistyped and the 6 should have been 5.

--


Gary

"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Contrary to what the help file says, I don't think the 4th argument has any
> bearing on the return value from the DatePart function when the first argument
> is "w" (try all the possible arguments for the 4th argument... for a given
> date and start of week, you will always get the same value). Now, as to what
> the function is returning... I don't think it is doing what you seem to think
> it is. With the "w" argument, it is giving you the weekday number of the date
> you provide with the count starting as indicated by the 3rd argument. So, for
> this...
>
> DatePart("w", DateSerial(2009, 1, 1), vbMonday, vbFirstFullWeek)
>
> it returns 4 because the January 1, 2009 occurs on a Thursday which is the 4th
> day of the week when the week starts on Monday (Monday is 1, Tuesday is 2,
> Wednesday is 3 and Thursday is 4). As for this...
>
> DatePart("w", DateSerial(2010, 1, 1), vbMonday, vbFirstFullWeek)
>
> you said it returns 6, but actually, it returns 5 and that is because January
> 1, 2010 occurs on Friday and Friday is the 5th day of the week when the week
> starts on a Monday.
>
> --
> Rick (MVP - Excel)
>
>
> "Gary Keramidas" <GKeramidasAtMsn.com> wrote in message
> news:ObV%(E-Mail Removed)...
>> can someone explain what i am seeing?
>>
>> this expression returns 4
>> DatePart("w", DateSerial(2009, 1, 1), vbMonday, vbFirstFullWeek)
>>
>> the 1st is on thursday and the first monday is the 5th, which is 4 days
>> later.
>>
>> but this expression returns 6, which doesn't make sense to me. i would think
>> it would return 3
>> DatePart("w", DateSerial(2010, 1, 1), vbMonday, vbFirstFullWeek)
>>
>> so, i guess i'm missing something.
>>
>>
>> --
>>
>>
>> Gary
>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
DatePart question =?Utf-8?B?UmVuZWU=?= Microsoft Access Queries 1 13th Feb 2006 10:53 PM
DatePart question obembe Microsoft Access Queries 4 21st Mar 2005 06:43 PM
DatePart question =?Utf-8?B?VG9ydHVyZWRTb3Vs?= Microsoft Access Getting Started 4 15th Dec 2004 01:21 PM
DatePart Question =?Utf-8?B?RVRTaGVybWFu?= Microsoft Access 1 30th Nov 2004 10:19 PM
DatePart Question question about Datepart Microsoft Access VBA Modules 3 14th Jan 2004 08:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 AM.