Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Two digit week numbers in VB

Hi everyone.

I am currently using the following code to obtain two digit week numbers in
excel. Is there an easier or cleaner way of doing it?

If Len(DatePart("WW", Now())) < 2 Then _
maxDate = DatePart("YYYY", Now()) & " 0" & _
DatePart("WW", Now()) _
Else maxDate = DatePart("YYYY", Now()) & " " & _
DatePart("WW", Now()) _


Thanks,

John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Two digit week numbers in VB

John
?format(DatePart("WW", Now()),"00")

NickHK

"John Ortt" wrote in message
...
Hi everyone.

I am currently using the following code to obtain two digit week numbers

in
excel. Is there an easier or cleaner way of doing it?

If Len(DatePart("WW", Now())) < 2 Then _
maxDate = DatePart("YYYY", Now()) & " 0" & _
DatePart("WW", Now()) _
Else maxDate = DatePart("YYYY", Now()) & " " & _
DatePart("WW", Now()) _


Thanks,

John




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Two digit week numbers in VB

Public Function IsoWeekNum(d1 As Date) As Integer
Dim d2 As Long
d2 = DateSerial(Year(d1 - Weekday(d1 - 1) + 4), 1, 3)
IsoWeekNum = Int((d1 - d2 + Weekday(d2) + 5) / 7)
End Function

Code will be:

wNum = IsoWeekNum(Now())
WeekNum = wNum
if wNum < 10 then WeekNum = "0" & wNum


John Ortt wrote:
Hi everyone.

I am currently using the following code to obtain two digit week numbers in
excel. Is there an easier or cleaner way of doing it?

If Len(DatePart("WW", Now())) < 2 Then _
maxDate = DatePart("YYYY", Now()) & " 0" & _
DatePart("WW", Now()) _
Else maxDate = DatePart("YYYY", Now()) & " " & _
DatePart("WW", Now()) _


Thanks,

John


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Two digit week numbers in VB

Thanks Nick,

That did the trick

"NickHK" wrote in message
...
John
?format(DatePart("WW", Now()),"00")

NickHK



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
entering 16 digit numbers - last digit turns to zero dreamer New Users to Excel 4 May 9th 09 01:04 AM
16 digit numbers Rich[_8_] Excel Discussion (Misc queries) 11 November 30th 08 03:29 AM
Store numbers starting with zero as 2 digit numbers twisted1825 Excel Discussion (Misc queries) 8 January 11th 07 06:41 PM
what is the minimum numbers set for 4 digit numbers from 0000 to 9 Ambika Excel Discussion (Misc queries) 14 January 27th 06 10:50 PM
16 DIGIT NUMBERS IN CELL WITHOUT LAST DIGIT BEING A ZERO jnkell Excel Worksheet Functions 2 December 18th 04 07:13 PM


All times are GMT +1. The time now is 12:02 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"