Add One Day (24 Hours) To A Date From

Oct 26, 2003

I'm having some trouble getting a grip on PHP's date handling. I've got my dates stored in a MySQL "datetime" column and I'm wondering, what is the best way to add one day (24 hours) to a date from that column?

View 5 Replies


Add Hours To A Date

I want to show a date coming from mysql (datetime format) to users, logging on from different timezones. Each user has it's own time:When a user logs on a session is created which hold the the time difference from the servertime e.g. user John has $_SESSION['mytime']=2; which means user John is in a timezone 2 hours later than the server.

Now if a servertime gives a datetime value of 2002-20-10 18:15:05 How can I make it display 2 hours later, so it will show 2002-20-10 20:15:05? I know mysql has a Date_add function, but I want to keep my queries as they are already, and keep my datedifferences calculation in my include file. So I am looking for a PHP-coded solution.

View 10 Replies

Date() Being Off By 23 Hours

I have the Unix time stamp "1184616000" which I place into date('F j, Y h:i:s A', 1184616000) and I have tested it on two servers which produce "July 17, 2007 12:00:00 AM" but on some other servers it produces "July 16, 2007 01:00:00 PM". Since it is a pregenerated timestamp the date() output should be identical regardless of where it is executed. I am trying to figure out which is right and which is wrong. Can some people please try this out and let me know what you get?

View 6 Replies

Date() Output 23 Hours Behind

Using a UNIX timestamp for "June 26, 2007, 12:00:00 AM" I compared the output of two calls to the date() function. One on a Windows server running PHP 5.2.1 and another on a Linux server running 5.0.5. The output on the Linux server is 23 hours behind the output of the Windows server, showing "June 25, 2007, 1:00:00 AM".

The code is identical. Only the PHP and Apache version and the operating system vary. Time zone is not a factor as this is a pregenerated integer value for a future date. What could be causing this discrepancy?

View 3 Replies

Print A Date Just Like Eg:2 Hours Ago Mar 10?

function timeSpent($date_created, $endingDay)
$diff = abs(strtotime($date_created) - strtotime(date("Y-m-d H:i:s")));
$years = floor($diff / (365 * 60 * 60 * 24));
$months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
$days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
$hours = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24) / (60 * 60));......

View 1 Replies

Getting Amount Of Hours Since Date?

A database where I store times with the Now(); function.What I want is:When the viewer looks at the post, instead of it saying:Posted:2010-11-14 19:08:14, I want it to say posted:x hours ago, Posted: x days ago, etc.

View 4 Replies

Adding 12 Hours To Date?

I have the below code wish I wish to add 12 hours to:

Code: [Select]$today = date('D', mktime(0,0,0,date('m'),date('d')+0,date('Y')));

show how I add 12 hours?

View 1 Replies

Mktime, Date, And Adding Hours

I want to take the current time and add 8 hours using the following format: PHP Code:

View 5 Replies

Date() Function, Add A Couple Of Hours To It

The default timestamp that date() uses is the current time of the server which is processing the PHP document. So I wonder if I can add a coupla hours to this time? Say I need these 2 lines on my page:

Here it is 1:00 pm, November 25, 2005 ------ date('g:i a, F j, Y');
There it is 4:00 pm, November 25, 2005 ----- date('g:i a, F j, Y', ???)

View 2 Replies

Subtract 24 Hours From A Date Time?

I'm trying to subtract exactly 24 hours from a timestamp.

2012-09-22 19:15:00

subtracted 24 hours with code below =>

2012-09-21 07:09:00 which is not what I want it to be I need it to be 2012-09-21 19:15:00


$dato_begivenhed = $row['event_date'];
echo $dato_begivenhed;
echo "<br>";
$date = new DateTime($dato_begivenhed);
$date->modify("-24 hours");
echo $date->format("Y-m-d h:m:s");

View 4 Replies

Pull YYYY From 'DATE' & Sum Of Hours

I am having difficult combining 2 functions. On their own, each works fine. I would like to sum all of the hours within a certain event type based on the current year. Year = in table as DATE type and formatted as 2011-05-01.

My current code to sum the hours is:
Code: [Select]<?php
// Make a MySQL Connection
mysql_connect("localhost", "$user", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());


View 3 Replies

The Time That Is Left Until The Date Reaches 24 Hours

How would I display the time that is left until the date reaches 24 hours? 16 hours 8 min(s) until you get me back. PHP Code:

View 9 Replies

Timezone - Adding 8 Hours To A Date Field?

I am having troubles adjusting my code to allow for a different time zone. My client's site is in Australia but the mysql server is in the Netherlands, which is 8 hours behind. Each day they want to display which users birthdays is on the current date which is working fine, adding the extra 8 hours to make up the time difference.

Here is my code,

mysql_select_db($database_ambassador_db, $ambassador_db);
$query_rs_tbl_birthdays = "SELECT real_name FROM tbl_ambassadors WHERE dob = CURDATE() ORDER BY real_name ASC";
$rs_tbl_birthdays = mysql_query($query_rs_tbl_birthdays, $ambassador_db) or die(mysql_error());


View 2 Replies

Date Difference In Hours With A Working Twist?

I'm working on a script which will loop through all emails that have come in and then it tries to work out how long in hours it was until a reply was sent, this was fairly straight forward using the function I have below where I just pump in two dates and it spits out a value of how many hours it took.

However, this isn't good enough for the needs of the script. We work in the office from 9 till 5.30 from monday to friday, what I now need to do is work out how many WORKING HOURS there was between the two dates and times I give it.

Code: [Select]
function timeDiff($firstTime,$lastTime)
// convert to unix timestamps
// perform subtraction to get the difference (in seconds) between times
// return the difference
return $timeDiff;

View 5 Replies

Check Date And Time And Display A Link Between Certain Hours

I need to write a PHP script that can check the date and time, and if it falls in between certain hours to display a link, and if not display another link.

The application is for a realaudio broadcast which goes live 7-9pm every wednesday. If it's not "live" then the link would be to the archive from the previous show.

View 1 Replies

Subtract 12 Hours And 30 Minutes From The Date Sat, 30 Apr 2011 05:00:00 -0400?

I have the sample date in the format "Sat, 30 Apr 2011 05:00:00 -0400". I need to reduce / subtract 12hours and 30 minutes from this date in the run time before i store this data into my database using PHP.

View 4 Replies

Datetime - Add Hours To Date Output Wrong Result?

Basically what I want to do is to send an email to follow up on order placed in 3 hours later.

What I try to do is to get the current date (up to hours level), then compare with the orderdate+ 3 hours, to see whether it match.

Example orderdate: 2010-06-12 18, after add 3 hours should become 2010-06-12 21

However, after add hour, the final result sometimes become bigger, sometimes become smaller... something wrong.

$now= date('Y-m-d H');
echo $now . "<br>";
while ($data = mysql_fetch_array ($result))
$orderid = $data['orderid'];


View 2 Replies

Save Every 6 Hours A RSS Feed And Rename It To The Current Date?

I am displaying some RSS feeds in my site that I have them in an array. I am researching on how to improve the script by creating an archive system for the previous day and save the RSS feeds I use into a folder for further use.

What I know is to show the posts of the feeds sorted by date. What I don't know is how to save an array of RSS feeds every let's say 6 hours in the same folder I have the script. I don't mind if the job is made through cron or manually by me.

Perhaps a solution is to create a single feed with all the feeds combined that will be renamed by the script in a date format structure like 11072011.xml

After 6 hours there will be a new feed that must be saved. So, either will be combined to the previous one (I dont mind if there are same entries) or the system must create a new file called 110720112.xml (2 is the increment number) with all the posts of my feeds array.

If this is the way of solution (and not combining them), the first XML file should have at the end number 1 like 110720111.xml and so on for sorting purposes.

What I imagine is having in the code all the rss feeds I use and create a cron job that will save them into the same folder.

I know how to use

file_get_contents(); and file_put_contents(); but just a bit about the between of them.

View 3 Replies

Compare Dates - Add Number Of Hours For Each Division On A Particular Date

MSQL 5.1.36 PHP 5.3.0 I have my php script that tried to add number of hours for each division on a particular date. For example , I want to find the number of hours worked by IT division from $start_date = "2010-07-01" to $end_date = "2010-07-04". Lets say there are 4 IT staff working on the start date "2010-07-01", I want to calculate their hours add them up and store it into the array. After that I have to increment date and do another calculation for IT staff i.e calculate their hours and them up and store into the same array....


View 1 Replies

Subtracting A Certain Number Of Hours / Days / Months Or Years From Date?

I'm trying to create a simple function which returns me a date with a certain number of subtracted days from now, so something like this but I dont know the date classes well:

function get_offset_hours ($hours) {
return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
function get_offset_days ($days) {


Is it possible to do something similar to this? this kind of function works for years, but how to do the same with other time types?

View 3 Replies

Datetime - Working With Dates - How Many Hours Old Is Date / Time Stamp

I am storing a Date/Time in a MySQL TEXT field. I want to be able to check if the date stored in the database is atleast 48 hours from the current date/time. Here is some code:

$dtformat = "F jS, Y - g:i A";
$datetime = date($dtformat);

The value of $datetime is sent to MySQL and placed in a TEXT column, I would use MySQL DATETIME, but the timezone needs to be different, depending on the users location. So I figured I would make my timestamp in PHP. An example output would be January 11th, 2011 - 6:24 PM How would I take the current date/time in PHP and find out if my timestamp January 11th, 2011 - 6:24 PM is atleast 48 hours old?

View 3 Replies

Extracting Weeks / Days / Hours / Minutes From A Date Calc

$dateDiff = $mtime - $ctime;
$fullDays = floor($dateDiff/(60*60*24));
$fullHours = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
echo "Difference is $fullDays days, $fullHours hours and $fullMinutes minutes.";

I am looking to add the ability to see weeks as well. I know I could just repeat the same process, but is there a library or an easier way?

View 1 Replies

Find Difference In Hours- Edit Code From Days To Hours?

I'm trying to find the difference in hours between one date from another, and my code currently finds the difference in days- could somebody edit the code to use hours instead of days?

$expirationdate[0] = $row3[datetillcompletion];
$startdate[0] = date('Y-m-d');
$startdate = strtotime($startdate[0]);
$expirationdate = strtotime($expirationdate[0]);
$delta = $expirationdate - $startdate;

View 3 Replies

Date / Time - Changes In The County Records And Their Server Time Is Two Hours Different From Mine

I have a batch script that reads from a timestamp.txt file to determine the last time it ran and I need to modify that by two hours. What happens is the script will run to look for changes in the county records and their server time is two hours different from mine.

Code: [Select]$fr=fopen("xml/timestamp.txt",'r');
$mydate=fread($fr, 50);
if ($incremental_updates == 1){
$contest=str_replace("{DATE_TAG}", $mydate, $contest);

I tried making a time stamp update look like $cur_timestamp=date("Y-m-d H:i:s", time() +14400); which is correct but it doesn't write to the text file properly. Using the above fwrite($fw, substr(date('c'), 0, 19)); I get the correct results in the timestamp.txt file for my server time. I need it to be +14400 2011-05-25T08:27:51 would essentially become 2011-05-25T10:27:51 when it writes to the timestamp.txt

View 3 Replies

Relative Date Formatting Always Outputs "3 Hours Ago"?

I am calculating the date interval between a specified date and the current date using php. I do this so I can print out social friendly timestamps like A few mins ago and 2 hours agoWhen I come to the hours part I get something behaving real funny in php. Below is the full working code but when you replace the hours part with this code it always prints out 3 hours.Defined constant DATE

// The current date timestamp
define('DATE', time());

Buggy code here:

//Only the hours part that' doing something weird
case ($interval >= 3600 && $interval < 86400) :
$return = ( date('H', $interval) < 2)


View 6 Replies

Converting Past Date To "x Hours Ago"?

I'm trying to write a function that will compare two dates and return a string based date (for example, "21 hours ago", "Wednesday at 3:03pm"), and beyond one week it returns the date and time instead. (Similar to that of FaceBook's date display system, indicating when an event occured, if that clarifies what I want)The function needs to take the date in question in MYSQL TIMESTAMP format (2010-07-10 10:10:49) and today's date in the MYSQL TIMESTAMP format.

View 3 Replies

Copyrights 2005-15, All rights reserved