Jump to content


Photo

Check date in php


  • Please log in to reply
11 replies to this topic

#1 barber84

barber84

    Young Padawan

  • Members
  • Pip
  • 8 posts

Posted 10 December 2005 - 07:15 PM

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

#2 barber84

barber84

    Young Padawan

  • Members
  • Pip
  • 8 posts

Posted 10 December 2005 - 08:57 PM

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.

#3 Forgotten

Forgotten

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 11 December 2005 - 02:10 AM

just to add another question to this post, how do I turn GMT into -8:00 (PST)?

#4 barber84

barber84

    Young Padawan

  • Members
  • Pip
  • 8 posts

Posted 11 December 2005 - 03:03 AM

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)

?>

#5 Forgotten

Forgotten

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 11 December 2005 - 03:34 AM

my script shows
$Time=date("g:i A T");
will echo

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.

#6 Av-

Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,972 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 11 December 2005 - 07:14 AM

to set a timezone use

<?php
date_default_timezone_set('PST');

date(stuff);
?>

Edited by Avalanche, 11 December 2005 - 07:15 AM.


#7 Forgotten

Forgotten

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 11 December 2005 - 12:31 PM

yeah that is an undefined function... Im using php 5.1

#8 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 11 December 2005 - 04:06 PM

Just use barbers method, with a little tweaking.
echo date('g:i A', time()-(60*60)).' PST';

Edited by rc69, 11 December 2005 - 04:08 PM.


#9 Forgotten

Forgotten

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 12 December 2005 - 08:17 PM

thanks rc69!

check it out: www.adminalliance.net

:unsure:

#10 phpguy

phpguy

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 27 October 2009 - 06: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

#11 Arctic Fire

Arctic Fire

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 27 October 2009 - 10:05 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.

#12 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 27 October 2009 - 10:07 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users