/ Forside / Teknologi / Udvikling / PHP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
PHP
#NavnPoint
rfh 3959
natmaden 3372
poul_from 3310
funbreak 2700
stone47 2230
Jin2k 1960
Angband 1743
Bjerner 1249
refi 1185
10  Interkril.. 1146
Finde dage ud fra Uge nummer.
Fra : Supremacy2k


Dato : 02-08-05 05:38

Ville bare lige høre om det er muligt at finde dato'erne i en given uge.

f.eks:
Uge 31 (Denne Uge) består af: 1-7 August.
Uge 32 består af 8-14 August.
Uge 48 består af 28-30 November og 1-4 December.

osv osv osv. ;)



 
 
Martin (01-08-2005)
Kommentar
Fra : Martin


Dato : 01-08-05 22:12

Supremacy2k wrote:
> Ville bare lige høre om det er muligt at finde dato'erne i en given uge.
>
> f.eks:
> Uge 31 (Denne Uge) består af: 1-7 August.
> Uge 32 består af 8-14 August.
> Uge 48 består af 28-30 November og 1-4 December.
>
> osv osv osv. ;)
>
>

$ugenr = date("w",mktime($time,$minut,$sekund,$dag,$måned,$år));

Sådan :)

Kig evt på
www.php.net/date
www.php.net/mktime

Supremacy2k (02-08-2005)
Kommentar
Fra : Supremacy2k


Dato : 02-08-05 06:19

"Martin" <news@natten-i.dk> wrote in message
news:42ee9018$0$22189$edfadb0f@dread16.news.tele.dk...
> Supremacy2k wrote:
>> Ville bare lige høre om det er muligt at finde dato'erne i en given uge.
>>
>> f.eks:
>> Uge 31 (Denne Uge) består af: 1-7 August.
>> Uge 32 består af 8-14 August.
>> Uge 48 består af 28-30 November og 1-4 December.
>>
>> osv osv osv. ;)
>>
>>
>
> $ugenr = date("w",mktime($time,$minut,$sekund,$dag,$måned,$år));
>
> Sådan :)
>
> Kig evt på
> www.php.net/date
> www.php.net/mktime

desværre Martin, du gør det stikmodsatte af hvad jeg vil... du finder
ugenummer ud fra en dato.

jeg vil have dato ud fra ugenummer. :)



Martin (02-08-2005)
Kommentar
Fra : Martin


Dato : 02-08-05 00:43

Supremacy2k wrote:
> desværre Martin, du gør det stikmodsatte af hvad jeg vil... du finder
> ugenummer ud fra en dato.
>
> jeg vil have dato ud fra ugenummer. :)
>

Hovsa :D

Nå men fandt lige en comment i mktime

<?php

# Get a date by providing a week number, day of week and a year.

# Be careful! There are different definitions for weeks. Here the
European definition is used.
# In Europe a week starts on Monday.
# Also the start of the first week in a year is defined differently in
different countries.
# Here the ISO 8601 definition is used. This is the standard in Europe.
#
# I got the information from
http://home.t-online.de/home/PeterJHaas/delphi.htm
# There are many websites with information on week numbers.
# An excellent site on this subject is
http://www.pjh2.de/datetime/weeknumber/index.php
#
# This PHP source was based on the Delphi source code by Peter J. Haas
#

//give me the date of Friday week 20 of the year 2004 (Should result in
Friday May 14 2004)
$aWeek=20; $aDay=05; $aYear=2004;
$adate=datefromweeknr($aYear, $aWeek, $aDay);
echo 'The date (week='.$aWeek.' day='.$aDay.' year= '.$aYear.') is
'.date('D d-m-Y',$adate).'<br>';

function datefromweeknr($aYear, $aWeek, $aDay)
{
$FirstDayOfWeek=1; //First day of week is Monday
$BaseDate=4; //We calculate from 4/1 which is always in week 1
$CJDDelta=2415019; //Based on start of Chronological Julian Day
$StartDate = DelphiDate(mktime(1,0,0,01,$BaseDate,$aYear)); //The date
to start with
$Offset = ($aWeek-1) * 7 - mod(floor($StartDate) + $CJDDelta + 8 -
$FirstDayOfWeek,7) + $aDay - 1;
return PHPUnixTimeStamp($StartDate + $Offset);
}

#---------extra functions used----------

function DelphiDate($aPHPTime)
{
# The Unix Timestamp holds the number of seconds after January 1 1970
01:00:00
return div($aPHPTime,86400)+25569;
}

function PHPUnixTimeStamp($aDelphiDate)
{
# Delphi's TDate holds number of days after December 30 1899
return ($aDelphiDate-25569)*86400-3600;
}

function mod($number, $div)
{
return $number - floor($number/$div)*$div;
}

function div($number, $div)
{
return floor($number/$div);
}

?>

Supremacy2k (02-08-2005)
Kommentar
Fra : Supremacy2k


Dato : 02-08-05 09:06

"Martin" <news@natten-i.dk> wrote in message
news:42eeb338$0$85009$edfadb0f@dread16.news.tele.dk...
> Supremacy2k wrote:
>> desværre Martin, du gør det stikmodsatte af hvad jeg vil... du finder
>> ugenummer ud fra en dato.
>>
>> jeg vil have dato ud fra ugenummer. :)
>>
>
> Hovsa :D
>
> Nå men fandt lige en comment i mktime
>
> <?php
>
> # Get a date by providing a week number, day of week and a year.
>
> # Be careful! There are different definitions for weeks. Here the
> European definition is used.
> # In Europe a week starts on Monday.
> # Also the start of the first week in a year is defined differently in
> different countries.
> # Here the ISO 8601 definition is used. This is the standard in Europe.
> #
> # I got the information from
> http://home.t-online.de/home/PeterJHaas/delphi.htm
> # There are many websites with information on week numbers.
> # An excellent site on this subject is
> http://www.pjh2.de/datetime/weeknumber/index.php
> #
> # This PHP source was based on the Delphi source code by Peter J. Haas
> #
>
> //give me the date of Friday week 20 of the year 2004 (Should result in
> Friday May 14 2004)
> $aWeek=20; $aDay=05; $aYear=2004;
> $adate=datefromweeknr($aYear, $aWeek, $aDay);
> echo 'The date (week='.$aWeek.' day='.$aDay.' year= '.$aYear.') is
> '.date('D d-m-Y',$adate).'<br>';
>
> function datefromweeknr($aYear, $aWeek, $aDay)
> {
> $FirstDayOfWeek=1; //First day of week is Monday
> $BaseDate=4; //We calculate from 4/1 which is always in week 1
> $CJDDelta=2415019; //Based on start of Chronological Julian Day
> $StartDate = DelphiDate(mktime(1,0,0,01,$BaseDate,$aYear)); //The date
> to start with
> $Offset = ($aWeek-1) * 7 - mod(floor($StartDate) + $CJDDelta + 8 -
> $FirstDayOfWeek,7) + $aDay - 1;
> return PHPUnixTimeStamp($StartDate + $Offset);
> }
>
> #---------extra functions used----------
>
> function DelphiDate($aPHPTime)
> {
> # The Unix Timestamp holds the number of seconds after January 1 1970
> 01:00:00
> return div($aPHPTime,86400)+25569;
> }
>
> function PHPUnixTimeStamp($aDelphiDate)
> {
> # Delphi's TDate holds number of days after December 30 1899
> return ($aDelphiDate-25569)*86400-3600;
> }
>
> function mod($number, $div)
> {
> return $number - floor($number/$div)*$div;
> }
>
> function div($number, $div)
> {
> return floor($number/$div);
> }
>
> ?>

Okey kigger lige på det, for tror at det er det her, har ellers siddet og
gloet på mktime, date, getDate osv osv osv. ;)



Kai Birger Nielsen (02-08-2005)
Kommentar
Fra : Kai Birger Nielsen


Dato : 02-08-05 11:49

In <42eeb88d$0$18645$14726298@news.sunsite.dk> "Supremacy2k" <Supremacy2k@gmail.com> writes:

>Okey kigger lige på det, for tror at det er det her, har ellers siddet og
>gloet på mktime, date, getDate osv osv osv. ;)

Lige en advarsel om at tænke over hvordan output bliver brugt.
Fx ligger 29. december 2003 i uge 1 i 2004.
Den 1. januar 2006 ligger i uge 52 i 2005, mens den
25 december 2006 ligger i uge 52 i 2006.

mvh Birger Nielsen (bnielsen@daimi.au.dk)

Henrik Blunck (02-08-2005)
Kommentar
Fra : Henrik Blunck


Dato : 02-08-05 12:36

Kai Birger Nielsen skrev Tirsdag den 2. august 2005 12:48 i beskeden
<dcnj21$brg$2@news.net.uni-c.dk> i gruppen
dk.edb.internet.webdesign.serverside.php:

> In <42eeb88d$0$18645$14726298@news.sunsite.dk> "Supremacy2k"
> <Supremacy2k@gmail.com> writes:
>
>>Okey kigger lige på det, for tror at det er det her, har ellers siddet og
>>gloet på mktime, date, getDate osv osv osv. ;)
>
> Lige en advarsel om at tænke over hvordan output bliver brugt.
> Fx ligger 29. december 2003 i uge 1 i 2004.
> Den 1. januar 2006 ligger i uge 52 i 2005, mens den
> 25 december 2006 ligger i uge 52 i 2006.
>
> mvh Birger Nielsen (bnielsen@daimi.au.dk)

Ja, uge-nr problematikken gør næsten at man skal danne et array ud fra en
kendt uge - f.eks. at vi nu befinder os i uge 31. Det bliver noget af en
tabel... :'-(

--
Med venlig hilsen
Henrik Blunck
Vil du vide mere om Linux - http://www.linux-svar.dk
Oversættelse af manualer m.v. - http://www.blunck.dk/firma

Christian Hansen (02-08-2005)
Kommentar
Fra : Christian Hansen


Dato : 02-08-05 14:40

Hejsa

Måske dette kan bruges:

http://chrsen.dk/fundanemt/files/scripter/php/misc/weekDates.php

Mvh Christian

Supremacy2k wrote:
> Ville bare lige høre om det er muligt at finde dato'erne i en given uge.
>
> f.eks:
> Uge 31 (Denne Uge) består af: 1-7 August.
> Uge 32 består af 8-14 August.
> Uge 48 består af 28-30 November og 1-4 December.
>
> osv osv osv. ;)
>
>

Bo Meyer (02-08-2005)
Kommentar
Fra : Bo Meyer


Dato : 02-08-05 15:15

Christian Hansen wrote:

> http://chrsen.dk/fundanemt/files/scripter/php/misc/weekDates.php

Funktionen er fin og enkel! Men, hvad gør man mod inddata som ikke findes? Eksempel: Uge 53 År 2006
= Uge starter d. 2009-12-28 og slutter d. 2010-01-03

Mvh. Bo

Christian Hansen (02-08-2005)
Kommentar
Fra : Christian Hansen


Dato : 02-08-05 16:13

Bo Meyer wrote:
> Funktionen er fin og enkel! Men, hvad gør man mod inddata som ikke
> findes? Eksempel: Uge 53 År 2006 = Uge starter d. 2009-12-28 og slutter
> d. 2010-01-03

Det må man sørge for at tjekke, inden man tager funktionen i brug. Denne
funktion skal ikke andet end at returnere start- og slutdato for en
given uge - om ugen er gyldig, kan man lave en anden funktion til at
tjekke - keep it simple nemlig :)

Man kan jo også bare tjekke om uddata er rimeligt i forhold til inddata,
ved at tjekke om inddataårstallet findes i en af de 2 uddatadatoer - gør
den det, er det ok.

Tjabum.

Mvh Christian



Supremacy2k (02-08-2005)
Kommentar
Fra : Supremacy2k


Dato : 02-08-05 22:54


"Supremacy2k" <Supremacy2k@gmail.com> wrote in message
news:42ee87bf$0$18636$14726298@news.sunsite.dk...
> Ville bare lige høre om det er muligt at finde dato'erne i en given uge.
>
> f.eks:
> Uge 31 (Denne Uge) består af: 1-7 August.
> Uge 32 består af 8-14 August.
> Uge 48 består af 28-30 November og 1-4 December.
>
> osv osv osv. ;)
>

har faktisk løst det med denne her:

<?php

echo $_REQUEST['week'] . "<br><br>\n";

?>

<?php

# Get a date by providing a week number, day of week and a year.

# Be careful! There are different definitions for weeks. Here the European
definition is used.
# In Europe a week starts on Monday.
# Also the start of the first week in a year is defined differently in
different countries.
# Here the ISO 8601 definition is used. This is the standard in Europe.
#
# I got the information from
http://home.t-online.de/home/PeterJHaas/delphi.htm
# There are many websites with information on week numbers.
# An excellent site on this subject is
http://www.pjh2.de/datetime/weeknumber/index.php
#
# This PHP source was based on the Delphi source code by Peter J. Haas
#

//give me the date of Friday week 20 of the year 2004 (Should result in
Friday May 14 2004)
$aWeek = $_REQUEST['week'];
$aYear = $_REQUEST['year'];

for ($i = 1; $i <= 7; $i++) {
$adate=datefromweeknr($aYear, $aWeek, $i);
echo 'The date (week='.$aWeek.' day='.$i.' year= '.$aYear.') is '.date('D
d-m-Y',$adate).'<br>';
}

function datefromweeknr($aYear, $aWeek, $aDay)
{
$FirstDayOfWeek=2; //First day of week is Monday
$BaseDate=4; //We calculate from 4/1 which is always in week 1
$CJDDelta=2415019; //Based on start of Chronological Julian Day
$StartDate = DelphiDate(mktime(1,0,0,01,$BaseDate,$aYear)); //The date to
start with
$Offset = ($aWeek-1) * 7 - mod(floor($StartDate) + $CJDDelta + 8 -
$FirstDayOfWeek,7) + $aDay - 1;
return PHPUnixTimeStamp($StartDate + $Offset);
}

#---------extra functions used----------

function DelphiDate($aPHPTime)
{
# The Unix Timestamp holds the number of seconds after January 1 1970
01:00:00
return div($aPHPTime,86400)+25569;
}

function PHPUnixTimeStamp($aDelphiDate)
{
# Delphi's TDate holds number of days after December 30 1899
return ($aDelphiDate-25569)*86400-3600;
}

function mod($number, $div)
{
return $number - floor($number/$div)*$div;
}

function div($number, $div)
{
return floor($number/$div);
}

?>

problemet er bare nu at den viser 1januar 2006 som uge 1, og 2-8 januar som
uge 1. :(

Ved ikke helt hvorfor, det er en del i kalenderen, og ikke i scriptet der
finder datoerne i ugenummeret.



Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste