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?

ADVERTISEMENT

Add Hours To A Date

Sep 30, 2002

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 View Related

Date() Being Off By 23 Hours

Jun 28, 2007

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 View Related

Date() Output 23 Hours Behind

Jun 7, 2007

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 View Related

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

May 16, 2011

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 View Related

Getting Amount Of Hours Since Date?

Nov 14, 2010

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 View Related

Adding 12 Hours To Date?

May 5, 2011

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 View Related

Mktime, Date, And Adding Hours

Mar 24, 2006

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

View 5 Replies View Related

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

Nov 15, 2005

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 View Related

Subtract 24 Hours From A Date Time?

Sep 29, 2009

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

Code:

$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 View Related

Pull YYYY From 'DATE' & Sum Of Hours

Jun 2, 2011

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
include('dbconfig.php');
// Make a MySQL Connection
mysql_connect("localhost", "$user", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());

[Code]...

View 3 Replies View Related

The Time That Is Left Until The Date Reaches 24 Hours

Mar 20, 2006

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 View Related

Timezone - Adding 8 Hours To A Date Field?

Apr 18, 2010

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,

<?php
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());

[Code]....

View 2 Replies View Related

Date Difference In Hours With A Working Twist?

Jul 12, 2011

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
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;
// return the difference
return $timeDiff;
}

View 5 Replies View Related

Check Date And Time And Display A Link Between Certain Hours

Apr 7, 2002

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 View Related

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

Apr 24, 2011

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 View Related

Datetime - Add Hours To Date Output Wrong Result?

Jun 12, 2010

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'];

[Code]....

View 2 Replies View Related

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

Jul 11, 2011

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 View Related

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

Jul 17, 2010

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....

[Code]....

View 1 Replies View Related

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

Mar 4, 2010

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) {

[Code]....

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 View Related

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

Jan 12, 2011

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:

<?php
date_default_timezone_set("America/New_York");
$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 View Related

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

Jul 27, 2010

$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 View Related

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

Sep 4, 2007

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;
$final=round($delta/86400);

View 3 Replies View Related

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

May 25, 2011

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){
$default_template_file="xml/incremental_template.xml";
$default_config_name="xml/incremental.xml";
$contest=file_get_contents($default_template_file);
$contest=str_replace("{DATE_TAG}", $mydate, $contest);
[Code].....

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 View Related

Relative Date Formatting Always Outputs "3 Hours Ago"?

Jun 28, 2011

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)

[code]...

View 6 Replies View Related

Converting Past Date To "x Hours Ago"?

Jul 9, 2010

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 View Related

Dates 23.00 Hours To 0.00 Hours.

May 14, 2007

I have the following code

$day1 = mktime (0,0,0,1,1,$year);
$days = ($week - 1) * 7;
$d = strtotime ("+$days days", $day1);
$dow = date('w', $d);
$sunday = strtotime ("-$dow days", $d);
$saturday = strtotime ("+6 days", $sunday);

to give me the timestamp on sunday and saturday for a given week and year. The problem I have is that it's giving it at 23.00 hours when i need it at 0.00 hours.

1179010800 translates to Saturday, May 12th 2007, 23:00:00 (GMT)

Can anyone see the problem?

View 1 Replies View Related

Hours &

Jan 31, 2007

I'm selecting from a database a time looks like this: 1170229906. I'm trying to find a way to print the hours & minuted differences between each couple, when I'm using while

($rs=mysql_fetch_assoc($result)) {.

For example, if the first time is 1170229906 and the second is 1170240253 - the result should be 2:53.

View 3 Replies View Related

Restarting Every 24 Hours

Jan 3, 2001

How would i reset a .txt file with a number in it to 0 ever 24 hours?

View 2 Replies View Related

Add 16 Hours To Datetime

Dec 5, 2000

I have a mysql database table that gets the "datetime" column automatically filled when a user fills in the php form page.

$curdate = date("Y-m-d H:i:s");

Trouble is, the database server is in the USA which is 16 hours behind my time. Does anyone know a way to change this so that the 16 hours get added to the datetime?

View 2 Replies View Related

Mins To Hours

Sep 21, 2005

i have a form when submitted hte php file the data is picked up by uses the timespan function to work out the time between two times given byt the user then it converts it into minutes. no on anouther page i want to be abe to convert it back into hours but when i put /60 after the variable it doesnt work it out correctly instead of the time being 11:59 hours it says 11.983333333333 . so how can i get it to convert back into 11:59?

View 3 Replies View Related

Convert Hours

Jul 15, 2006

I've been trying to figure it out for hours and I'm tired because I know it isn't that difficult. guess it's just late and I can't think right.

Anyways, so I have a lot of hours. Let's go with 8786 hours for example. I need to convert that to look like"___ years ____ days ____ hours".

View 1 Replies View Related

Add 24 Hours To A Timestamp

Jul 6, 2005

i want to add 24 hours to a timestamp. how can i do? i searched the php manual.

View 3 Replies View Related

Detect 6 Hours From Now

Nov 13, 2005

I'm doing a time ban and so when a user is banned obviously for datebanned i have time(). So on my unban list I basically want to take the time() function and add 6 hours to it so it still stays in the number format and then insert it into my database. How can I add hours and so forth accurately?

View 1 Replies View Related

Hours To Man Days

Jun 30, 2007

I know this is prob easy but i've looked around and can't find what i am looking for, plus i'm a little bit of a newb. I have a group of total hours for a bunch of workers,, i.e each is like 280 hrs and i need to display these set of hours in another way, i need to display them in total man days instead and a man day for me is 6.5 hours now i know i can just divide 280 by 6.5 in php but that gives me something like:

43.076923076923076923076923076923 i need it to output in a format something like 43 days + 1 hour (or minutes if less than an hour)

View 5 Replies View Related

Counting Hours.

Jun 22, 2006

I have a Rota Submission page, which allows staff members to submit changes in rota, detailing their hours (start and finish), with additional hours if they're doing shifts, or an option for not being online at all. Code:

View 11 Replies View Related

Time Is Off By 2 Hours?

Jul 20, 2007

Whenever I create a new php file and use the date function like so

<?php echo date("g:i"); ?>

My browser outputs the correct time (I believe i am GMT-5:00) the first few times the file is opened, then the time becomes slow by 3 hours every time it loads (ex: 7:00pm my time shows up as 4:00pm on the browser screen). Is there a simple way to add 3 hours in the date function?

View 5 Replies View Related

Adding 2 Hours To Now()?

May 24, 2011

in my MySql database i have a field "created_at" = now() for ex: 2011-05-23 11:47:28 i need to add two hours to that so i have 2011-05-23 13:47:28 i have this so far but it is not correct:

$currentTime = time($msg->getCreatedAt());
$timeAfterOneHour = $currentTime+60*60;
$date=date("Y-m-d H:i:s",$timeAfterOneHour);

View 2 Replies View Related

Adding 12 Hours To NOW()?

Sep 29, 2010

The following code allows a list of seminars to display on a homepage:

$sql = 'SELECT ID,title,division,startdate,enddate,time,location 
FROM event 
WHERE category="1" AND startdate > NOW()
ORDER BY startdate, enddate 
LIMIT 4';

The first seminar will only show up until the time of the conference. I would like for it to display for 12 hours after the conference occurs. How do I make that happen?

View 3 Replies View Related

Add 13 Hours To A Timestamp?

Jul 14, 2009

I have a table with timestamp values like:

2009-07-14 02:00:00

I need to display them at run time with 13 hours added, like:

2009-07-14 15:00:00

View 6 Replies View Related

How To Add 2 Hours In Doctrine

Jun 6, 2011

With the following code,

protected $token;
/** @Column(name="assigneddate", type="datetime", columnDefinition="datetime") */
private $assigneddate;

[code]....

How do I add 2 hours to this?

View 2 Replies View Related

Validate Something After 24 Hours?

Jun 21, 2011

i have php app where i want to check something after 24 hours or on daily bases. i have a columns in database lastscan in which the last scan time stored i only want to know in PHP how to trigger the check after 24 hours passed want to run a php task every 24 hours

View 4 Replies View Related

Update Every 24 Hours

Apr 28, 2009

I have an sql for example

Code: $q = mysql_query("UPDATE visit_table SET visit=visit+1 WHERE id>100");

How can I update (run $q) it EVERYDAY at 00:00:01 (h:i:s) for ONE time?

View 4 Replies View Related

Allow To Edit Within X Hours

Jul 18, 2007

I have data that is inserted into a database, one of the fields is named 'time_stamp' and is a "datetime; 0000-00-00 00:00:00" type.

I was wondering how one could make an if statement that will show code (code is just the editing portion of the page) if the 'time_stamp' is less than the 'time_stamp' + 72 hours. Other wise, don't show the code and inform them that they can no longer edit.

View 2 Replies View Related

Adding Hours To Time

May 11, 2003

Whats the most effective way of adding 3 hours to a time in the format of 1:30 (h:mm), and turning it into a 24 hour format?

I was thinking of turning it into a timestamp and working from there, but it seems a bit inefficient.

View 1 Replies View Related

ADVERTISEMENT