jeudi 16 juillet 2020

writing if, else on date

I used Codeigniter and Gammu to make the SMS autoreplay feature. The format in SMS is: DAFTAR#NIK#NAME#DATE

With the date format yyyy-mm-dd. I used the date taken from the #DATE text in the if statement.

if($tanggal_periksa==$dataku)

is true if the date entered has a range of seven days from the current date. example: now on 2020-07-17. the if statement is true if we use the date 2020-07-17 to 2020-07-23. other than that date then it is worth wrong. but when I use a date in the span of seven days it is still wrong.

    {
        $inboxs= $this->db->get_where('inbox', array('Processed'=>'false'));
        foreach ($inboxs->result() as $inbox)
        {
            $pesan= $inbox->TextDecoded;
            $no_hp = $inbox->SenderNumber;
            $pecah = explode("#", $pesan);
            $key=$pecah[0];
            $keyword=trim($key);
            if(strtoupper($keyword)=='DAFTAR')
            {
                if(count($pecah)==4)
                {
                    $NIK=trim($pecah[1]);
                    $nama=$pecah[2];
                    $tanggal_periksa=$pecah[3];// i got it from #DATE
                    $tahun = date('Y');
                    $bulan = date('m');
                    $tanggal = date('d');
                    $format = $tahun.'-'.$bulan.'-'.$tanggal;
                    $seminggu = abs(6*86400);
                    $awal = strtotime($format);
                    $akhir = strtotime($format)+$seminggu;
                    $sub_kalimat = substr($tanggal_periksa,4,1);
                    $sub_kalimat1 = substr($tanggal_periksa,7,1);
                    $jumlah_karakter = strlen($tanggal_periksa);
                    // echo "<br>".$akhir;
                    if($jumlah_karakter==10 && $sub_kalimat=="-" && $sub_kalimat1=="-")//done
                    {
                        for($i=$awal; $i <=$akhir;$i+=86400)
                        {
                            $dataku=date('Y-m-d', $i);
                            if($tanggal_periksa==$dataku)
                            {

Aucun commentaire:

Enregistrer un commentaire