Mengubah Format Tanggal Pada PHP

Seperti yang kita ketahui format Penanggalan pada MySQL menggunakan format Tahun-Bulan-Tanggal.Ini menjadi tidak lazim di Indonesia. Karena format yang biasa kita gunakan adalah Tanggal-Bulan-Tahun.



Untuk itu agar memudahkan saat menginput tanggal kita bisa saja mengubah dengan format Tanggal-Bulan-Tahun. Contohnya seperti tampilan berikut



Tetapi masalahnya timbul saat kita akan memasukan data tanggal tersebut ke database MySQL. Oleh karena itu, kita mesti mengubah format date menjadi Tahun-Bulan-Tanggal kembali saat proses insert ke database.Berikut ini contoh script singkatnya.


<?php
if (isset($_POST['submit'])){
$tgl = $_POST['tgl'];
$date = date_create($tgl);
echo date_format($date, 'Y-m-d');
}else{
?>
<html>
<head>
<link type="text/css" href="jqueryui/css/south-street/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="jqueryui/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jqueryui/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type='text/javascript'>
    $(document).ready(function(){
    $("#date").datepicker({dateFormat:"dd-mm-yy"});
 });
</script>
</head>
<body>
<form method="post" action="test.php">
 <input type="text" name="tgl" id='date'>
 <input type="submit" name="submit">
</form>
</body>
</html>
<?php
}
?>

Dan saat kita klik submit query, maka format date berubah sesuai dengan format date pada MySQL kembali

Source Code
?>
Category:
Reaksi: 

6 komentar:

cobacoba.coba2 mengatakan...

thanks

Anonim mengatakan...

okeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

Anonim mengatakan...

MAACIH OM

Anonim mengatakan...

Matur suwun sanget

Ratnasari Kamil mengatakan...

Teman - teman kesulitan untuk Belajar Komputer karena kesibukan? kini kami memfasilitasi kursus komputer jarak jauh via online, silahkan kunjungi website kami di asianbrilliant.com, Kursus Online

Ayah, Bunda..butuh guru untuk mengajar anak-anak dirumah ? kami memfasilitasi 1000 guru untuk anak-anak ayah dan bunda datang kerumah, silahkan kunjungi website kami di smartsukses.com, Bimbingan Belajar, Les Private

Anonim mengatakan...

baguuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuus

Poskan Komentar