Avatar billede Slettet bruger
08. august 2002 - 18:30 Der er 15 kommentarer og
1 løsning

Formel for ugedag?

Hvordan er det nu formelen er for at regne ud hvilken ugedag(man-tirs-ons-tors-fre-lør-søndag) det er en givet dato?

Gerne et link til en side.
Avatar billede a1a1 Novice
08. august 2002 - 18:35 #1
ASP?

oder was?
Avatar billede Slettet bruger
08. august 2002 - 18:37 #2
Nope, en alm. formel udregnigen.

Man kan via dato, mnd og år, regne ud hvilken dag det var/er/bliver.
Avatar billede a1a1 Novice
08. august 2002 - 18:42 #3
asp:

Weekday(date, [firstdayofweek])

hvor date er en dato.
firstdayofweek kan have disse værdier (brug tallet)

firstdayofweek
a constant that specifies the first day of the week. If omitted, vbSunday is assumed.

vbUseSystem 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

du skal så også bruge funktionen weekdayname
WeekdayName(weekday, abbreviate, firstdayofweek)

Arguments
weekday

Required. The numeric designation for the day of the week. Numeric value of each day depends on setting of the firstdayofweek setting.

abbreviate

Optional. Boolean value that indicates if the weekday name is to be abbreviated. If omitted, the default is False, which means that the weekday name is not abbreviated.

firstdayofweek

Optional. Numeric value indicating the first day of the week. See Settings section for values.

Her er et eksempel:
<%
dato = Date
dagtal = WeekDay(dato,0)
Response.Write dagtal & "<br />"
dagnavn = WeekDayName(dagtal)
Response.Write dagnavn & "<br />"
%>
Avatar billede nih Novice
08. august 2002 - 18:43 #4
du er vel nødt til at have en reference dato

lave en beregning ud fra den: (Xdato - refDato) mod 7

Niels
Avatar billede a1a1 Novice
08. august 2002 - 18:44 #5
hmmmm, en formel?

den kender jeg ikke til (der er som du kan se jo også forskel på hvilken dag der er den første i ugen? så resultatet vil jo være afhængig af hvilken dag der nu er den første i ugen)
Avatar billede Slettet bruger
08. august 2002 - 18:49 #6
ehh.. tak.. men det er ik' i noget programmeringssporg... :o)

Jeg ved der findes sådan en formel.. fik den i folkeskolen engang.. meen kan sq ik' huske den mere.. :o(
Avatar billede Slettet bruger
08. august 2002 - 18:50 #7
Den tog også højte for skudår
Avatar billede Slettet bruger
08. august 2002 - 18:54 #8
Avatar billede Slettet bruger
08. august 2002 - 18:56 #9
magik> sad selv og kiggede på den side.. men det var ik' den :o(
Avatar billede a1a1 Novice
08. august 2002 - 18:56 #10
der noget her:

What day of the week will it be, a year from today?

Suppose that today is February 13, 2053. The day of the week is a Thursday. One week (seven days) from today, on February 20, 2053, it will be Thursday again. After two weeks (fourteen days), it will be Thursday once more. We need to figure out how many weeks and days will have passed after a year. 2053 is not a leap year, so 365 days will pass between February 13, 2053 and February 13, 2054. Let's divide by 7 to find out how many weeks that is: 365 / 7 = 52, remainder 1, or fifty-two weeks with one day left over. Fifty-two weeks after February 13, 2053 is yet another Thursday, so fifty-two weeks and one day later must be a Friday.

We can use the same method for any date, but we have to be careful. Because some years are leap years, a year from today might be 366 days and not 365. For instance, there are 366 days between Saturday, November 20, 2055 and November 20, 2056, because 2056 is a leap year and February 29, 2056 lies between the two Novembers.

fra:
http://mathforum.org/dr.math/faq/faq.calendar.html

http://mathforum.org/
http://mathforum.org/library/topics/cals_dates_time/branch.html

ellers kig på det site :)
Avatar billede a1a1 Novice
08. august 2002 - 18:58 #11
zeller formula...

How do I find the day of the week for any date?

There are two popular formulas that you can use to find the day of the week for a given date. You should be careful when you use these formulas, though, because they only work for the Gregorian calendar. (People in English-speaking countries used a different calendar before September 14, 1752.)

Zeller's Rule

The following formula is named Zeller's Rule after a Reverend Zeller. [x] means the greatest integer that is smaller than x. You can find this number by just dropping everything after the decimal point. For example, [3.79] is 3. Here's the formula:

f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C.

k is the day of the month. Let's use January 29, 2064 as an example. For this date, k = 29.
m is the month number. Months have to be counted specially for Zeller's Rule: March is 1, April is 2, and so on to February, which is 12. (This makes the formula simpler, because on leap years February 29 is counted as the last day of the year.) Because of this rule, January and February are always counted as the 11th and 12th months of the previous year. In our example, m = 11.
D is the last two digits of the year. Because of the month numbering, D = 63 in our example, even though we are using a date from 2064.
C stands for century: it's the first two digits of the year. In our case, C = 20.
Now let's substitute our example numbers into the formula.

f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C
= 29 + [(13*11-1)/5] + 63 + [63/4] + [20/4] - 2*20
= 29 + [28.4] + 63 + [15.75] + [5] - 40
= 29 + 28 + 63 + 15 + 5 - 40
= 100.

Once we have found f, we divide it by 7 and take the remainder (if the remainder is negative, add 7). A remainder of 0 corresponds to Sunday, 1 means Monday, etc. For our example, 100 / 7 = 14, remainder 2, so January 29, 2064 will be a Tuesday.

The Key Value Method

This method uses codes for different months and years to speed up the calculation of the day of the week. You might even be able to memorize the codes. We'll use December 16, 2482 as an example.

Take the last 2 digits of the year. In our example, this is 82.


Divide by 4, and drop any remainder. 82 / 4 = 20, remainder 2, so we think "20."


Add the day of the month. In our example, 20 + 16 = 36.


Add the month's key value, from the following table.
Jan Feb Mar Apr May June July Aug Sept Oct Nov Dec
1 4 4 0 2 5 0 3 6 1 4 6


The month for our example is December, with a key value of 6. 36 + 6 = 42.


If your date is in January or February of a leap year, subtract 1. We're using December, so we don't have to worry about this step.


Add the century code from the following table. (These codes are for the Gregorian calendar. The rule's slightly simpler for Julian dates.)
1700s 1800s 1900s 2000s
4 2 0 6


Our example year is 2482, and the 2400s aren't in the table. Luckily, the Gregorian calendar repeats every four hundred years. All we have to do is add or subtract 400 until we have a date that is in the table. 2482 - 400 = 2082, so we look at the table for the 2000s, and get the code 6. Now we add this to our running total: 42 + 6 = 48.


Add the last two digits of the year. 48 + 82 = 130.


Divide by 7 and take the remainder. This time, 1 means Sunday, 2 means Monday, and so on. A remainder of 0 means Saturday. 130 / 7 = 18, remainder 4, so December 16, 2482 will be on the fourth day of the week-- Wednesday.
Avatar billede Slettet bruger
08. august 2002 - 19:11 #12
a1> Den ligner godt nok meget... men er næsten sikker på den jeg havde var der (ÅR-1)/4 - (ÅR-1)/100 + (ÅR-1)/400 til sidst i den...
Avatar billede a1a1 Novice
08. august 2002 - 19:13 #13
der er to :)
også The Key Value Method

men jeg viste faktisk ikke at man kunne det men fandt bare dem her :)
Avatar billede a1a1 Novice
12. august 2002 - 00:59 #14
?

var det ikke godt nok ?
Avatar billede Slettet bruger
12. august 2002 - 08:17 #15
Jow, det ser ik' ud til andre kan komme med noget bedre, og jeg har ik' selv kunne finde den som jeg havde den gang :o(
Avatar billede a1a1 Novice
12. august 2002 - 08:32 #16
;)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester