pengurangan Tanggal

Asratul Hamdi · Jun 15, 2012
mas saya ada koding kyak gini :
<?php 
$id = $_GET['id'];

$query = mysql_query("select * from pasien where no_rm='$id'") or die(mysql_error());

$data = mysql_fetch_array($query);
$pecahTanggal1 = explode("-", $data['tgl_keluar']);
$tanggal1 = $pecahTanggal1[2];
$bulan1   = $pecahTanggal1[1];
$tahun1   = $pecahTanggal1[0];
?>


<form name="input_data" action="insertpasien.php" method="post">
<input type="hidden" name="no_rm" value="<?php echo $id; ?>" />
<table width="442" border="0" cellpadding="5" cellspacing="0">
    <tbody>	
        <tr>
		   <tr>
        	<td width="208">Nomor RM Pasien</td>
        	<td width="7">:</td>
        	<td width="585"><input type="text" name="no_rm" maxlength="20" required="required" value="<?php echo $data['no_rm']; ?>" disabled /></td>
        </tr>
		</tr>
        <tr>
        	<td width="130">Cara Bayar</td>
        	<td width="7">:</td>
        	<td width="281"><input type="text" name="cara_byr" maxlength="20" required="required" disabled/></td>
        </tr>
		<tr>
		<tr>
        	<td width="130">tgl keluar</td>
        	<td width="7">:</td>
        	<td width="281"><input type="text" name="tgl_keluar" maxlength="20" required="required" disabled/></td>
        </tr>
		<tr>
			<td>Tanggal Pengembalian berkas</td>
			<td>:</td>
			<td>
				
			<?php
				echo "<select name=tanggal1>
						<option value=0>Tanggal</option>";
				for($no=1;$no<=31;$no++)
				{
					echo "<option value=$no>$no</option>";	
				}
				
				echo "</select>";
				
				$nama_bln = array(1=> "Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober",
									  "November","Desember");
				echo "<select name=bulan1>
						<option value=0>Bulan</option>";
				for($no=1;$no<=12;$no++)
				{
					echo "<option value=$no>$nama_bln[$no]</option>";	
				}
				echo "</select>";
				
				$thn_skrg = date("Y");
				echo "<select name=tahun1>
						<option value=0>Tahun</option>";
				for($no=1989;$no<=$thn_skrg;$no++)
				{
					echo "<option value=$no>$no</option>";	
				}
				
				echo "</select>";
			?>
			</td>
		</tr>
        <tr>
        	<td width="130">Keterlambatan</td>
        	<td width="7">:</td>
        	<td width="281"><input type="text" name="no_rm" maxlength="20" required="required" disabled/></td>
        </tr>
		
		<td>&nbsp;</td>
		<tr>		
        	<td align="left" colspan="3"><input type="submit" name="submit" value="Simpan" /></td>
        </tr>
    </tbody>
</table>
</form>

jadi data tanggal keluar akan diambil dari database, kemudian data tanggal pengembalian diinput, didapatlah keterlambatan(dlm hitungan hari) hasil dari tanggal keluar - tanggal pengembalian(tgl_keluar-tgl_dikembalikan = keterlambatan)

ini tablenya mas :
CREATE TABLE `pasien` (
  `no_rm` varchar(15) collate latin1_general_ci NOT NULL,
  `nm_pasien` varchar(45) collate latin1_general_ci NOT NULL,
  `umur` varchar(5) collate latin1_general_ci NOT NULL,
  `jns_pasien` varchar(25) collate latin1_general_ci NOT NULL,
  `cara_byr` varchar(25) collate latin1_general_ci NOT NULL,
  `tgl_masuk` date NOT NULL,
  `tgl_keluar` date NOT NULL,
  `kd_penyakit` varchar(15) collate latin1_general_ci NOT NULL,
  `kd_dokter` varchar(15) collate latin1_general_ci NOT NULL,
  `kd_ruangan` varchar(15) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`no_rm`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Jun 26, 2012 · 0 Suka · 0 Tidak Suka