comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: days of the week
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: days of the week [message #29884 is a reply to message #29849] Mon, 25 March 2002 09:07 Go to previous message
Martin Downing is currently offline  Martin Downing
Messages: 136
Registered: September 1998
Senior Member
OK, how about an amalgam of David's and Craigs methods:

FUNCTION WhatDayIsIt, jul_day = jdate, year=year, month=month, day=day,
NUMBER=NUMBER
;+
; Return the day of the week given either the JULDATE
; or
; the date as DAY , MONTH, YEAR
; NUMBER: return the number of days from sunday instead of the string day
name
;-

; convert input to julday
IF N_Elements(jdate) EQ 0 THEN begin
if N_Elements(day) EQ 1 THEN begin
jdate = Julday(month, day, year)
endif else begin
jdate = Systime(/Julian)
endelse
endif

; Julday of any old Sunday
jdate_sunday =2452358L ;= Julday(3,24,2002)

; What day of the week is it? (note the use of round)
dow = ( (round(jdate) - jdate_sunday ) mod 7 )
dow = (dow +7 ) mod 7

if keyword_set(NUMBER) EQ 0 then begin
; return a string day-name
daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', $
'Thursday', 'Friday', 'Saturday']
dow = daysOfWeek[dow]
endif

RETURN, dow

END
IDL> print, WhatDayIsIt(jul = systime(/jul))

Monday

IDL> profiler, /report

Module Type Count Only(s) Avg.(s) Time(s) Avg.(s)

WHATDAYISIT (U) 1 0.000065 0.000065 0.000065 0.000065


--
----------------------------------------
Martin Downing,
Clinical Research Physicist,
Grampian Orthopaedic RSA Research Centre,
Woodend Hospital, Aberdeen, AB15 6LS.


"trouble" <the_cacc@hotmail.com> wrote in message
news:5f9f0a23.0203210321.25c748ff@posting.google.com...
> David Fanning <david@dfanning.com> wrote in message
news:<MPG.17025cedc0db98d798983c@news.frii.com>...
>>
>> P.S. Sorry for the FOR loop. I was in a hurry. :-(
>>
>
> Tsk, according to my timings that FOR loop is costing us 0.0009 seconds.
> Maybe OK for some, but what if ya gots to know the day *now*? Maybe also
> consider using IntArr(7,/NOZERO)? ;)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: A little handy date function
Next Topic: Re: IDL Movie Viewer

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 21:56:36 PDT 2025

Total time taken to generate the page: 0.87099 seconds