Help - Search - Members - Calendar
Full Version: Check date in php
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
barber84
Hi,

how would I use php to check a date in the format yyyy-mm-dd to see if it has been a week since that date.

thanks,

Ben
barber84
Problem resolved using:

echo date("Y-m-d",(time() + 60*60*24*30));

which displays today date + 30 days and I am using if else statements to see if todays date matches 30 days on from the date in the database.
Forgotten
just to add another question to this post, how do I turn GMT into -8:00 (PST)?
barber84
Hopefully this should help you, it just takes 8 hours away from the current time.

<?php

$time = time() - (60*60*8); //Take away 8 hours from the time the server is set to (GMT)

echo $time; // display time in PST (-8)

?>
Forgotten
my script shows
CODE
$Time=date("g:i A T");
will echo
QUOTE
2:53 PM MST


How do I make MST say PST? Isnt there a O operator that sets timezones? I don't know how to use it.
Av-
to set a timezone use

CODE
<?php
date_default_timezone_set('PST');

date(stuff);
?>
Forgotten
yeah that is an undefined function... Im using php 5.1
rc69
Just use barbers method, with a little tweaking.
CODE
echo date('g:i A', time()-(60*60)).' PST';
Forgotten
thanks rc69!

check it out: www.adminalliance.net

victory.gif
phpguy
Hi,
I'm working on a project that checks today's date against one in the mysql database. I can write a function in a php script to check. However if the php script is just sitting there; then what actually starts the process of the check function; besides an inefficient continuous loop?
Thanks

Arctic Fire
QUOTE (phpguy @ Oct 27 2009, 07:30 PM) *
Hi,
I'm working on a project that checks today's date against one in the mysql database. I can write a function in a php script to check. However if the php script is just sitting there; then what actually starts the process of the check function; besides an inefficient continuous loop?
Thanks

You would create a cron job to run the php script every day.
Demonslay
Well, either you can have it wrapped in a function that is invoked every time a page is loaded, such as in your main configuration file or something, or you can setup a cron job. I've personally never used a cron job, but its a way of automating something for the server to execute on a set interval. You can find several tutorials on these online if not here on P2L, such as this one if your host uses CPanel.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.