Solved

php: midnight

Posted on 2004-08-06
11
2,023 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
Industry Leaders: 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!

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 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