php dates and postgres
am 11.01.2007 21:37:00 von Natalie Leotta
------=_Part_33405_27406977.1168547820788
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hello,
I need to query my db to find out if an entry has been updated since a date
the user enters (mm/dd/yyyy).
Can I do something like the stuff below? Or do I need to do the extract
epoch stuff backwards somehow?
$timestamp = strtotime($user_date);
$postgres_format = date(format info that matches the postgres format,
$timestamp);
and then use $postgres_format to see if something is newer/older when I do
my SQL? When I enter things can I use something similar (if I can't use
now())?
Thanks!
Natalie
------=_Part_33405_27406977.1168547820788--
Re: php dates and postgres
am 12.01.2007 00:48:29 von dmagick
Natalie Leotta wrote:
> Hello,
>
> I need to query my db to find out if an entry has been updated since a date
> the user enters (mm/dd/yyyy).
>
> Can I do something like the stuff below? Or do I need to do the extract
> epoch stuff backwards somehow?
>
> $timestamp = strtotime($user_date);
> $postgres_format = date(format info that matches the postgres format,
> $timestamp);
>
> and then use $postgres_format to see if something is newer/older when I do
> my SQL? When I enter things can I use something similar (if I can't use
> now())?
Depends on how you're getting the $user_date.
If you have separate form fields for mm, dd & yyyy then you can just put
it all together.
$check_date = (int)$_POST['yyyy'] . '-' . (int)$_POST['mm'] .
(int)$_POST['dd'];
If you're getting it in one form field or a weird format, you will need
to do some sort of conversion to a 'standard' format.
Then when it comes time to do the query, it's simple if you store it in
date or timestamp format, you can just do:
select * from table where createdate > 'yyyy-mm-dd';
If you store epoch timestamps, then you'll need to convert it using
strtotime.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php