Wednesday, 26 March 2014


Bab 14


PHP Date()


 

Fungsi date() digunakan untuk memformat waktu dan tanggal.

 

Sintaks

date(format,timestamp)

 

Parameter
Keterangan
format
Required. Specifies the format of the timestamp
timestamp
Optional. Specifies a timestamp. Default is the current date and time (as a timestamp)

 

 

Timestamp


 

Timestamp adalah jumlah detik sejak January 1, 1970 00:00:00 GMT. Juga dikenal sebagai Unix Timestamp.

 

Format Tanggal


 

  • d – format hari (01-31)
  • m – format bulan (01-12)
  • Y – format tahun

 

Program14-1.php

<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
?>

 

output:

2006/07/11
2006.07.11
2006-07-11

Fungsi mktime() akan memberikan nilai Unix timestamp untuk tanggal tertentu.

Sintaks

mktime(hour,minute,second,month,day,year,is_dst)

 

Program14-2.php

<?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));

echo "Tomorrow is ".date("Y/m/d/", $tomorrow);
?>

 

output:

Tomorrow is 2006/07/12


Bab 14


PHP Date()


 

Fungsi date() digunakan untuk memformat waktu dan tanggal.

 

Sintaks

date(format,timestamp)

 

Parameter
Keterangan
format
Required. Specifies the format of the timestamp
timestamp
Optional. Specifies a timestamp. Default is the current date and time (as a timestamp)

 

 

Timestamp


 

Timestamp adalah jumlah detik sejak January 1, 1970 00:00:00 GMT. Juga dikenal sebagai Unix Timestamp.

 

Format Tanggal


 

  • d – format hari (01-31)
  • m – format bulan (01-12)
  • Y – format tahun

 

Program14-1.php

<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
?>

 

output:

2006/07/11
2006.07.11
2006-07-11

Fungsi mktime() akan memberikan nilai Unix timestamp untuk tanggal tertentu.

Sintaks

mktime(hour,minute,second,month,day,year,is_dst)

 

Program14-2.php

<?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));

echo "Tomorrow is ".date("Y/m/d/", $tomorrow);
?>

 

output:

Tomorrow is 2006/07/12


Bab 13

PHP $_POST

 

Variabel $_POST digunakan untuk mengambil data dari form yang dikirim menggunakan metode “post”.

 

Program13-1.php

<form action="Program13-2.php" method="post">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>

 

Bentuk URL yang dikirim.

http://localhost/Program12-2.php

 

Program13-2.php

Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!

 

 

Mengapa menggunakan $_POST?

  • Nama dan nilai variabel yang dikirim tidak diperlihatkan pada URL.
  • Jumlah variabel yang dikirim tidak terbatas.

 

Variabel $_REQUEST

 

Program13-3.php

Welcome <?php echo $_REQUEST["name"]; ?>.<br />
You are <?php echo $_REQUEST["age"]; ?> years old!

 

 
 















 





Blogger news

BTemplates.com

Powered by Blogger.

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Search This Blog

Pointer

Blogger Tricks

Popular Posts