Re: Week number with DatePart syntax, and Server...
- From: Benny Pedersen <b.pedersen@xxxxxxxxxx>
- Date: Sat, 22 Nov 2008 21:59:04 -0800 (PST)
On Nov 21, 10:24 pm, Dr J R Stockton <j...@xxxxxxxxxxxxxxxxxx> wrote:
In microsoft.public.scripting.vbscript message <bbb5af09-d799-4107-b3c0-SNIP
14bd865ed...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, Thu, 20 Nov 2008 22:08:24,
Benny Pedersen <b.peder...@xxxxxxxxxx> posted:
I friend of mine who work on a newspaper wanted a script to open
the latest folder. (week numbers included in folder names), so
I had to use the Datepart syntax.
No, you did not have to. It is easy enough to code it using simple
arithmetic and maybe DateSerial, Year, Month, Day, Date.
I expect you want the ISO 8601 Week Number, as is used throughout the
enlightened world; beware of answers from elsewhere, since those
southwest of Greenland frequently do not comply.
Don't use DatePart for ISO 8601 week numbers; it gets three days wrong
per 28 normal years, plus one per 400 years. Microsoft do have
alternative code; but AFAIK they still provide the inadequate version,
and their alternative is horribly bloated. Evidently it was written by
someone who does not use or understand 8601 - probably someone from
RAH's Lookout Mountain Avenue.
Instead, read <URL:http://www.merlyn.demon.co.uk/vb-date2.htm#DP>, but
start at the top of the page. Then use View Source, and seek
Sub WeekNumJRS(Tdy, YNo, WNo, DoW) '' Tdy is CDate in; Y W D out
&
function JRSWeekNum
You can also find a reverse function there. But test carefully.
How about a translation into Windows XP Batch?
ARGH. I now found that vbScript is better than XP batch... :)
Below is a new function with special code,
Dr J R Stockton, you know that I like to experiment, (or maybe you
have forgot me?)
Notice about the new funtion below:
If problems with the april/august exist in your
local language, just substitute the line:
case"A"X= mid("48",2+(left(X,2)="AP"),1)
with this instead:
case"A"X= mid("84",2+(left(X,2)="AU"),1)
Benny, (my e-mail address is outdated).
My Homepage: www.fineraw.com
=============================
Option explicit
' Below is a new function, someone maybe find it interesting ?
' The code is constructed in a way so it should also
' work good when a local language is specified such as Danish, etc...
' To let it return the number of a month,
' specify 3 or more characters in english, or another language:
msgBox DName("Jan","") ' return 01
msgBox DName("Feb","") ' return 02
msgBox DName("Mar","") ' return 03
msgBox DName("Apr","") ' return 04
msgBox DName("May","") ' return 05
msgBox DName("Jun","") ' return 06
msgBox DName("Jul","") ' return 07
msgBox DName("Aug","") ' return 08
msgBox DName("Sep","") ' return 09
msgBox DName("Oct","") ' return 10
msgBox DName("Nov","") ' return 11
msgBox DName("Dec","") ' return 12
' To let it return the name of a month, specify 2 digits:
msgBox DName("01","") ' return January
msgBox DName("01","local") ' return month in local language (da)
' Some extra (specify 1 digit):
msgBox DName("1","") ' return Monday
msgBox DName("1","local") ' return weekday in local language...
function DName(byVal X, byVal Lang)
if len(X) > 2 then
X= uCase(X)
select case left(X,1)
' Now some special syntax (me like to invent:)
case"J"X= mid("761",1-(mid(X,2,1)="A")-(mid(X,3,1)="N"),1)
case"M"X= mid("35",2+(left(X,3)="MAR"),1)
case"A"X= mid("48",2+(left(X,2)="AP"),1)
case"F"X= "2": case"S"X= "9": case"O"X= "10"
case"N"X= "11": case"D"X= "12"end select
DName= right("0"& X,2): exit function
else
' To let it return your local names, just substitute
' each X-ending with another word than Danish below:
select case cStr(X)
case "01" X= "January Januar"
case "02" X= "February Februar"
case "03" X= "March Marts"
case "04" X= "April April"
case "05" X= "May Maj"
case "06" X= "June Juni"
case "07" X= "July Juli"
case "08" X= "August August"
case "09" X= "September September"
case "10" X= "October Oktober"
case "11" X= "November November"
case "12" X= "December December"
case "1" X= "Monday Mandag"
case "2" X= "Tuesday Tirsdag"
case "3" X= "Wednesday Onsdag"
case "4" X= "Thursday Torsdag"
case "5" X= "Friday Fredag"
case "6" X= "Saturday Lørdag"
case "7" X= "Sunday Søndag"
end select
end if
' More somehow special syntax (still invented by meself of course:)
DName= split(X)(-cBool(inStr(1,Lang,"Local",1)))
end function
.
- Follow-Ups:
- Re: Week number with DatePart syntax, and Server...
- From: Dr J R Stockton
- Re: Week number with DatePart syntax, and Server...
- References:
- Week number with DatePart syntax, and Server...
- From: Benny Pedersen
- Re: Week number with DatePart syntax, and Server...
- From: Dr J R Stockton
- Week number with DatePart syntax, and Server...
- Prev by Date: Re: string manipulation
- Next by Date: Re: Week number with DatePart syntax, and Server...
- Previous by thread: Re: Week number with DatePart syntax, and Server...
- Next by thread: Re: Week number with DatePart syntax, and Server...
- Index(es):
Relevant Pages
|