Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

conditional behaviour on date

Community Beginner ,
Aug 10, 2007 Aug 10, 2007

Copy link to clipboard

Copied

I'm trying to set a 'show if conditional' behaviour based on the current date compared to the date in the database to determine if a link should show/not show - I don't think I'm using the date() correctly to find the current date - can anyone shed some light on this for me?

<?php
// Show IF Conditional region1
if (@$row_rs_open_mtg['date_agenda_mtg'] <= "date()") {
?>
<?php }
// endif Conditional region1
?>

Thanks, Bob
TOPICS
Server side applications

Views

656
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 10, 2007 Aug 10, 2007

Copy link to clipboard

Copied

taluswood wrote:
> I'm trying to set a 'show if conditional' behaviour based on the current date
> compared to the date in the database to determine if a link should show/not
> show - I don't think I'm using the date() correctly to find the current date -
> can anyone shed some light on this for me?

The PHP date() function is used to format a date. How you create a
conditional statement controlled by the current date depends on how the
date is stored in the database. Since you're using PHP, I assume that
the date is stored in MySQL in the standard MySQL format of YYYY-MM-DD.
If that is the case, change this:

> <?php
> // Show IF Conditional region1
> if (@$row_rs_open_mtg['date_agenda_mtg'] <= "date()") {
> ?>
> <?php }
> // endif Conditional region1
> ?>

to this:

<?php
if (strtotime($row_rs_open_mtg['date_agenda_mtg']) <= mktime(0,0,0)) {
// the date is earlier than today
}
?>

To compare the two values, you need to convert them to Unix timestamps.
strtotime() does that with a MySQL date, setting the time to midnight.
mktime(0,0,0) generates midnight at the start of the current day.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 10, 2007 Aug 10, 2007

Copy link to clipboard

Copied

On Fri, 10 Aug 2007 16:05:33 +0100, David Powers <david@example.com>
wrote:

><?php
>if (strtotime($row_rs_open_mtg['date_agenda_mtg']) <= mktime(0,0,0)) {
> // the date is earlier than today
> }
>?>
>
>To compare the two values, you need to convert them to Unix timestamps.
>strtotime() does that with a MySQL date, setting the time to midnight.
>mktime(0,0,0) generates midnight at the start of the current day.

Might be more efficient to just use the date function to format the date
as a MySQL date string:

if (@$row_rs_open_mtg['date_agenda_mtg'] <= date('Y-m-d')) {

However, it would probably be even more efficent to build it into the
query, so you wouldn't need the comparison here at all.

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 10, 2007 Aug 10, 2007

Copy link to clipboard

Copied

On Fri, 10 Aug 2007 12:21:29 -0500, Gary White <reply@newsgroup.please>
wrote:

>efficent

I'm so into efficiency that I've started conserving letters.

efficent can then be read as efficient.

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2007 Aug 13, 2007

Copy link to clipboard

Copied

Thanks David,
I got this to work:
if (strtotime(@$row_rs_open_mtg['date_agenda_mtg'] ) >= mktime(0,0,0)) {

and . . . yes it is more efficent !

cheers, Bob

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

.oO(taluswood)

>Thanks David,
>I got this to work:
>if (strtotime(@$row_rs_open_mtg['date_agenda_mtg'] ) >= mktime(0,0,0)) {
>
>and . . . yes it is more efficent !

It could be even more efficient to let the database do that kind of
work:

SELECT
IF(date_agenda_mtg >= CURDATE(), 1, 0) AS validDate,
...
FROM
...

Then in PHP:

if ($row_rs_open_mtg['validDate']) {
...
}

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

This is precisely what I'm trying to do except I don't understand how to code that parameter.
I have a record set called rs_ConcertNext
I want to show a record based on whether the date in that record set is greater than or equal to today.
Right now my record set just shows the first of many records. I don't want to repeat region here, just display the record that is greater than yesterday's date. Yes, in the MYSql database, my date is formated yyyy-mm-dd.
Thanks for any help.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 29, 2007 Aug 29, 2007

Copy link to clipboard

Copied

Two Oaks Jerseys wrote:
> I want to show a record based on whether the date in that record set is
> greater than or equal to today.
> Right now my record set just shows the first of many records. I don't want to
> repeat region here, just display the record that is greater than yesterday's
> date.

The best way to do that is by creating a SQL query that gets precisely
the information you want. Something like this should do it:

SELECT ConcertDate, Piece1, Piece2, Piece3
FROM table_name
WHERE ConcertDate >= CURDATE()
ORDER BY ConcertDate ASC
LIMIT 1

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2007 Aug 29, 2007

Copy link to clipboard

Copied

Yes, David, thank you. The SQL statement is exactly what I would do but I'm not sure how to place that inside my code. Do I call it as a variable? how do I enclose that statement into php? Right now the php statement does exactly the right thing, but that is of course because the database displays the first record. In order to stay current I'd have change the database as each date passes. The SQL statement would take care of that.. Just unclear of the syntax that calls it.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 30, 2007 Aug 30, 2007

Copy link to clipboard

Copied

LATEST
oboemuse@msn.com wrote:
> Yes, David, thank you. The SQL statement is exactly what I would do but I'm not
> sure how to place that inside my code.

You open the Recordset dialog box, click the Advanced button, and insert
the SQL. That's all.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines