[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

php: midnight

Posted on 2004-08-06
11
Medium Priority
?
2,030 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Independent Software Vendors: 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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

650 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