In mysql i store datetime like "2009-01-13 21:14:53" format. 1. When I call this date from php I want to add 15 days with that value and display the new datetime (including 15 days). Its may look like near "2009-01-28 21:14:53". 2. Before displaying the result of 'question-1' I want subtruct that result from current datetime and display the new result in days. let current datetime is "2009-01-20 20:12:33" Calcsequence : current datetime - (posted datetime + 15 days) The result will be something like - 8 days 3. Can I post current datetime from php something like this "5436543652" instead of "2009-01-20 20:12:33" ? If yes HOW ? 4. If questions-3 is YES how can i retrive again datetime like "2009-01-20 20:12:33" form data field "5436543652"? PLEASE HELM ME......
<?php $timestamp = time(); // current timestamp $15days = 86400 * 15; // 86400 is the same as 24 hours $result = $timestamp + $15days; echo "Now : ".$timestamp."<br>"; echo "15 days later : ".$result."<br>"; ?> PHP:
The first thing that you should do is convert '2009-01-13 21:14:53' (string) into timestamp (integer). If you've done it, you can do anything you want, get 15 days before it, 5 days after it, 5 hours after it, etc. First, convert string to integer <?php $yourDate = '2009-01-13 21:14:53';// this is your date $yourTimeStamp = strtotime($yourDate);// lets convert it to timestamp -- integer ?> PHP: Next, for example you want 5 days after $yourDate. We have to convert 5 days into seconds. Which means seconds = 5 * 24 * 3600. So here is 5 days after $yourDate <?php $secondsModification = 5 * 24 * 3600; // why i add, not substract, because it happens _AFTER_ a date // if it _BEFORE_ a date, substract it $newTimeStamp = $yourTimeStamp + $secondsModification; ?> PHP: Ok we've had the new timestamp, now you can display it on friendly date format <?php echo 'Yay ! '.date('r', $newTimeStamp); ?> PHP: About question number 3 & 4, i am not sure. Why don't you try it lol. If the inserted datetime is 0000-00-00, it means you can't Less than 1 minute to try
@activefrost, I think variables cannot start with number. Maybe change $15days to $fifteendays. Back to topic, Like how the above poster said, you can add seconds which is equivalent to the 15 days to the timestamp (which is also in seconds) or You can do this $yourDate = '2009-01-13 21:14:53'; $after_15_days = strtotime($yourDate." + 15 days"); PHP: To get it back in YYYY-MM-DD H:I:S format, $latest_date = date("Y-m-d H:i:s",$after_15_days); PHP: - ads2help