[SOLVED] How to get a date()?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] How to get a date()?

Post by $var »

G'day (Yar),

I have a member database that runs on membership.

I'm trying to insert the date ($today) automatically in 'active',
Add 1 Year ($nextyear), and insert that value into 'expire'.

These are the different ways I've tried it, and nothing is passing...

Code: Select all

<?php
$today = date("F j, Y, g:i a"); 
$nextyear = date("F j, Y+1, g:i a"); 
?>
or

Code: Select all

<?php
$today  = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));
$nextyear  = mktime(0, 0, 0, date("m"),  date("d"),  date("Y")+1);
?>
into

Code: Select all

<input class="text" name="active" type="hidden" id="active" value="<? $today ?>">
<input class="text" name="expire" type="hidden" id="expire" value="<? $nextyear ?>">
Last edited by $var on Thu Oct 06, 2005 12:50 pm, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

$var wrote:How to get a date
ermmm.... for this you will have to contact a dating company, or visit a dating site or try it out yourself :lol:

Well, seriously, why don't you use mysql built-in date functions NOW() & ADDDATE() to do that stuff :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

as a side note, the last php code block $var posted will not write anything into the output string for the values.. ;)
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

posted will not write anything into the output string for the values
wait, what won't it do?
i mean, i have found that nothing is passing, but is that just what you mean?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's right.. nothing will pass.. the values will be blank on the page.

Code: Select all

<input class="text" name="active" type="hidden" id="active" value="<?php echo $today; ?>">
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

feyd wrote:as a side note, the last php code block $var posted will not write anything into the output string for the values.. ;)
simply overlooked that :roll:
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

because they are hidden fields?
or because they are improper syntax?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

$var wrote:because they are hidden fields?
or because they are improper syntax?
because there is no echo or '='. without echo it outputs nothing that's why the blank output
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

so if i put <?php echo=('$today'); ?> it would pass something?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

$var wrote:so if i put <?php echo=('$today'); ?> it would pass something?
either

Code: Select all

<?php echo $today; ?>
or

Code: Select all

<?php =('$today') ?>
will work
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the second is a parse error (and will display the string $today, not the value inside ;)).. and the idea:

Code: Select all

<?= $somevar; ?>
only works when short tags are on. Since it's optional, it's recommended to always use the long form:

Code: Select all

<?php echo $somevar; ?>
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

egad 8O what is happening to me :? maybe that was drowsiness after a long day :(
Post Reply