Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,940 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,867 people online right now. Registration is fast and FREE... Join Now!




insert a 5 days becoming date

 
Reply to this topicStart new topic

insert a 5 days becoming date

imaro
16 Mar, 2008 - 11:16 AM
Post #1

New D.I.C Head
*

Joined: 16 Feb, 2008
Posts: 10


My Contributions
i want to insert the date 5 or 7 days after the date in my computer automatically...i mean not by select the date...
i cannot imagine how because if i add the date with the number 5,it will be effect by the day in each month...
so i dont know what to do

This post has been edited by imaro: 16 Mar, 2008 - 11:17 AM
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Insert A 5 Days Becoming Date
16 Mar, 2008 - 11:43 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
php
<?php

$newdate= mktime(0,0,0,date("m"),date("d")+5,date("Y"));
echo "The date after 5 days is ".date("d-m-Y", $newdate);

?>

User is offlineProfile CardPM
+Quote Post

imaro
RE: Insert A 5 Days Becoming Date
17 Mar, 2008 - 02:42 PM
Post #3

New D.I.C Head
*

Joined: 16 Feb, 2008
Posts: 10


My Contributions
i've try and it works...but how can i display the date with the my format..i mean that i convert the date to the my specific name like this....
so..using your code, i dont know how to apply my code....so can you please help me??

CODE

<?
#get the day and variable $hari will hold the full name of the day
$tm = date("D");
$hari = "";
if ($tm=="Sun")
  $hari ="Ahad";
else if ($tm=="Mon")
  $hari ="Isnin";
else if ($tm=="Tue")
  $hari ="Selasa";
else if ($tm=="Wed")
  $hari ="Rabu";
else if ($tm=="Thu")
  $hari ="Khamis";
else if ($tm=="Fri")
  $hari ="Jumaat";
else if ($tm=="Sat")
  $hari ="Sabtu";


//change the name of month to its full name
$tm = date("M");
$bln = "";
if ($tm == "Jan") {
  $bln = "Januari";
  $n_bln=01;
}
else if ($tm == "Feb"){
  $bln = "Februari";
  $n_bln=02;
}
else if ($tm == "Mar"){
  $bln = "March";
  $n_bln=03;
}
else if ($tm == "Apr"){
  $bln = "April";
  $n_bln=04;
}
else if ($tm == "May"){
  $bln = "Mei";
  $n_bln=05;
}
else if ($tm == "Jun"){
  $bln = "Jun";
  $n_bln=06;
}
else if ($tm == "Jul"){
  $bln = "Julai";
  $n_bln=07;
}
else if ($tm == "Aug"){
  $bln = "Ogos";
  $n_bln=08;
}
else if ($tm == "Sep"){
  $bln = "September";
  $n_bln=09;
}
else if ($tm == "Oct"){
  $bln = "Oktober";
  $n_bln=10;
}
else if ($tm == "Nov"){
  $bln = "November";
  $n_bln=11;
}
else if ($tm == "Dec"){
  $bln = "Disember";
  $n_bln=12;
}

#the  month and year  
$tgl = date("d");
$tm = date("Y");

#will combine 4 variable and show in one row
$modip =$tgl.' '.$bln.' '.$tm;
echo ("<br/><div align=\"center\">");
echo ("<font color=\"#000000\"><strong>".$hari.', '.$modip."</strong></font>");
echo ("</div>");
?>

User is offlineProfile CardPM
+Quote Post

_net
RE: Insert A 5 Days Becoming Date
17 Mar, 2008 - 03:23 PM
Post #4

D.I.C Head
**

Joined: 22 Sep, 2007
Posts: 146


My Contributions
Here is an easy way to select 5 days ahead:

CODE

echo "Time is: ".date("F j, Y, g:i a",time())."<br>";
echo "5 Days is: ".date("F j, Y, g:i a",strtotime("+5 day"))."<br>";


This post has been edited by _net: 17 Mar, 2008 - 03:24 PM
User is offlineProfile CardPM
+Quote Post

craig1709
RE: Insert A 5 Days Becoming Date
20 Mar, 2008 - 04:19 AM
Post #5

New D.I.C Head
*

Joined: 14 Jun, 2007
Posts: 18


My Contributions
date() takes two arguments. The string "D F Y" or whatever, and a timestamp. If you leave the timestamp out it defaults to the current timestamp.

So...you take MitkOK's code:
php

$newdate= mktime(0,0,0,date("m"),date("d")+5,date("Y"));


and put it before all your code. The change all your Date("whatever") to Date("whatever",$newdate).

So $tm = date("D"); would become $tm = date("D",$newdate);
User is offlineProfile CardPM
+Quote Post

imaro
RE: Insert A 5 Days Becoming Date
20 Mar, 2008 - 11:02 AM
Post #6

New D.I.C Head
*

Joined: 16 Feb, 2008
Posts: 10


My Contributions
QUOTE(craig1709 @ 20 Mar, 2008 - 05:19 AM) *

date() takes two arguments. The string "D F Y" or whatever, and a timestamp. If you leave the timestamp out it defaults to the current timestamp.

So...you take MitkOK's code:
php

$newdate= mktime(0,0,0,date("m"),date("d")+5,date("Y"));


and put it before all your code. The change all your Date("whatever") to Date("whatever",$newdate).

So $tm = date("D"); would become $tm = date("D",$newdate);




thank you...i got it... smile.gif smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:54PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month