-1
I think there’s a tapeworm using the if expression in style <?php if (mostrar depois de uma semana()): ?> Elemento aqui <?php endif; ?>
I have searched for everything that is singing and nothing. I am still a layman in it, but I learn fast.
-1
I think there’s a tapeworm using the if expression in style <?php if (mostrar depois de uma semana()): ?> Elemento aqui <?php endif; ?>
I have searched for everything that is singing and nothing. I am still a layman in it, but I learn fast.
4
"After a week" assumes you know of some way when you started counting this week.
Having the desired date, the base code is this:
<?php
if( date( 'Y-m-d' ) >= '2018-04-20' ) {
?>
<p>Seu HTML aqui</p>
<?php
}
?>
The function date
used this way returns a string, practice for
literal comparisons (date entered in the code).
It is important in this context that the date is always in year-to-day format,
because if you reverse the order, the logic of >=
loses its meaning.
If you are storing the current date, you can work with timestamps, for ease:
Code receiving current date:
$agora = time();
Calculating a week later:
$umasemanadepois = $agora + ( 7 * 24 * 60 * 60 );
Save that amount somewhere, you can’t put it in the code of if
but time
start will be restarted every time, never coming to "week after".
Applying in the if
:
<?php
if( time() >= $umasemanadepois ) {
?>
<p>Seu HTML aqui</p>
<?php
}
?>
Use gmdate()
if you want to skip local time zone;
in the case of time
is the reverse, the mktime
can be used for local spindle;
the time()
returns the date in seconds, so it is necessary to calculate one week to adjust:
7 * 24 * 60 * 60`
Seven days 24 hours 60 minutes 60 seconds
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
Post your code so we can help
– David Dias
Your question is very vague. Edit with more details, code and images if you find it necessary.
– hugocsl
I posted a generic solution, but the next questions should give more details. Fundamental read the [Tour], [Ask], [Help] and Manual on how NOT to ask questions for better use of the site.
– Bacco