Yılın Kaçıncı Haftasındayız

PHP
28 lines
<?php
class Haftabul {
var $damga;
function __construct($tarih){
if (is_int ($tarih))
$this->damga = $tarih;
else {
if (preg_match ("/^[\d]{4}\/([0]?\d|1[0-2])\/([1-2][0-9]|3[0-1]|[0]?[1-9])$/", $tarih)) {
$gecici = explode ("/", $tarih);
if (checkdate ($gecici [1], $gecici [2], $gecici [0]))
$this->damga = mktime (0, 0, 0, $gecici [1], $gecici [2], $gecici [0]);
}
}
}
function KacinciHafta(){
if (isset ($this->damga))
$tdamga = $this->damga;
else
return (false);
$gun = date ("z", $tdamga) + 1;
$hafta = ($gun >= 7 ? ceil ($gun / 7) : 1);
return $hafta;
}
}
$a=new Haftabul("2018/06/22");
echo $a->KacinciHafta();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
25
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Genişletilmiş Tarih Metni Sınıfı

PHP
49 lines
<?php
Class genisTarih {
var $data;
var $bol;
var $sonuc;
var $ay;
function gunu($gun){
switch ($gun){
case 1: $this->sonuc = "birinci"; break;
case 2: $this->sonuc = "ikinci"; break;
case 3: $this->sonuc = "üçüncü"; break;
case 4: $this->sonuc = "dördüncü"; break;
case 5: $this->sonuc = "beşinci"; break;
case 6: $this->sonuc = "altıncı"; break;
case 7: $this->sonuc = "yedinci"; break;
case 8: $this->sonuc = "sekizinci"; break;
case 9: $this->sonuc = "dokuzuncu"; break;
case 10: $this->sonuc = "on"; break;
case 20: $this->sonuc = "yirmi"; break;
case 30: $this->sonuc = "otuz"; break;
}
return $this->sonuc;
}
function gun($gun){
if(($gun - 30) > 0){
$this->sonuc = $this->gun(30)." ".$this->gun($gun - 30);
} elseif(($gun - 20) > 0){
$this->sonuc = $this->gun(20)." ".$this->gun($gun - 20);
} elseif(($gun - 10) > 0){
$this->sonuc = $this->gun(10)." ".$this->gun($gun - 10);
} else {
$this->sonuc = $this->gun($gun);
}
return $this->sonuc;
}
function ay($ay){
$this->ay = array('Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık');
$this->sonuc = $this->ay[floor($ay)-1];
return $this->sonuc;
}
function genisTarih($data){
$this->bol = explode("/", $data);
$gun = $this->gunu($this->bol[0]);
$this->sonuc = "Bugun ".$this->bol[2]." yılının ".$this->ay($this->bol[1])." ayının ".$gun." günündeyiz.";
echo ucfirst($this->sonuc);
}
}
new genisTarih(date("d/m/Y"));
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
Bugun 2018 yılının Haziran ayının ikinci günündeyiz.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Belirlenen Yıl ve Haftanın Hangi Günlere Arasında Olduğunu Bulma

PHP
26 lines
<?php
class gunlerarasiHafta{
function hesapla($yil, $hafta){
$yil = date('Y',mktime(0, 0, 0, 1, 1, $yil));
$ilkgunun = date('w',mktime(0, 0, 0, 1, 1, $yil));
$haftasonu = 7-$ilkgunun;
$song = date('Y/m/d',mktime(0, 0, 0, 1, $haftasonu, $yil));
if($hafta<54){
for($hft=2;$hft<=$hafta;$hft++){
$ilkgun = $haftasonu + 1;
$song = $ilkgun + 6;
$haftasonu = $song;
$ilkgun = date('Y/m/d',mktime(0, 0, 0, 1, $ilkgun, $yil));
$song = date('Y/m/d',mktime(0, 0, 0, 1, $song, $yil));
}
}
$tarih = array($yil, $ilkgun, $song);
return $tarih;
}
}
$yil = 2018;
$hafta = 20;
$a=new gunlerarasiHafta;
$tarih = $a->hesapla($yil, $hafta);
echo $yil." yılı ".$hafta.". hafta başlangıç günü ".$tarih[1]." ve bitiş günü ".$tarih[2];
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
2018 yılı 20. hafta başlangıç günü 2018/05/13 ve bitiş günü 2018/05/19
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX