?
Solved

php: midnight

Posted on 2004-08-06
11
Medium Priority
?
2,024 Views
Last Modified: 2008-02-26
I need to normalize my local time to midnight? How can I do so?
I would like to be able to choose today date.
here is my code:
*****************
 $T1date = strtotime($T1);
     $localtime = time();
     $localdate =  date('m/d/Y',$localtime);

          if($localtime > $T1date)
            {
             $validate = false;
             $error = 2;
            }
             $today = getdate();
             $month = $today['month'];
             $mday = $today['mday'];
             $year = $today['year'];
0
Comment
Question by:imaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 

Expert Comment

by:dubrie
ID: 11738545
You would probably have to do this in a cron job and have it set to run at midnight.  Cron jobs are somewhat readily available from hosting companies.
0
 

Expert Comment

by:dubrie
ID: 11738574
Here is a link that describes cron jobs pretty well:

http://www.bitfolge.de/pseudocron-en.html
0
 

Author Comment

by:imaw
ID: 11738584
all i want to do is be able  to choose today but I can't because no matter what, localtime will always be later than $T1 because it contains minutes seconds etc...
I knwo this possible without the hosting company.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11738594
Create a time value that represents today at midnight:

$localtime = strtotime('00:00');
0
 

Expert Comment

by:dubrie
ID: 11738614
Also, you can specify what to read in when you set the time/$localtime.  You can use the date() function and just grab an hour in either 12 or 24 hour format:

$12hourtime = date("h");

$24hourtime = date("H");

More specs on the date function can be found here:  http://us2.php.net/date
0
 

Author Comment

by:imaw
ID: 11738665
Is this close?
$T1date = mktime(0,0,0,$T1string[1],$T1string[2],$T1string[0]);


Squinky,
 can show an example with my code stated above?
0
 

Expert Comment

by:dubrie
ID: 11738693
To make midnight just do what he said:

$midnight = strtotime('00:00');
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11738751
No idea what you're doing there!

You can normalise $T1date the same way (as it appears to be a timestamp already):

$T1date = strtotime('00:00', $T1date);

alternatively, do the comparison with strings instead:

$localdate =  date('Y-m-d', $localtime);
$t1string =   date('Y-m-d', $T1date);
if($localdate > $T1string)

Because the strings are in ISO format (YYYY-MM-DD), they can be compared correctly.
0
 

Author Comment

by:imaw
ID: 11738811
where before all my code stated above?
it didn't work. that's why i need visual example.
0
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 2000 total points
ID: 11738883
I just didn't paste the bits that were the same...

$T1time = strtotime($T1);
$T1date = strtotime('00:00', $T1time)
$localdate =  strtotime('00:00');

          if($localdate > $T1date)
            {
             $validate = false;
             $error = 2;
            }
             $today = getdate();
             $month = $today['month'];
             $mday = $today['mday'];
             $year = $today['year'];

The only thing I'd say is that it's very unclear what you're actually trying to do. Although my example is syntactically ok, I couldn't tell you how useful it is logically as I don't know what you're trying to achieve.
0
 

Author Comment

by:imaw
ID: 11738943
Thanks.
as simple as that. that's all i neeeded.
it works perfect.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question