Jump to content

[SOLVED] PHP LOGIC


unknown1

Recommended Posts

Hello all, I was hoping someone could help me figure out the logic behind a script that

deletes a listing automatically after a 90 day time frame.

 

I have no clue on this so any input would be helpful.

 

e.g. how would I say

 

if(todays date == todays date + 90){

 

 

}

 

Not familiar with php date function so if someone could help that would be great.

 

Thanks in advance.

 

 

Link to comment
Share on other sites

yes I know that mysql has date time function but I'm having an issue submitting

it to the database.

 

e.g.

 

$sql = "insert into table (date)

VALUES ('????????')"; 

 

I don't understand how to use the function.

when I try something like

 

$sql = "insert into table (date) VALUES (date())";

 

I get an error even when I create a var like $date = date() I still get and error or 00-00-0000

in database.

 

can someone please elaborate on how to use these when submitting to a database...

 

Thanks in advance!

 

Link to comment
Share on other sites

oh ic it's because i did add a format  date("m.d.y") just had  date() so it was showing in the database as 00-00-0000 =) lol

 

Any idea of how I would go about counting 30 days from the date("m.d.y")??

Want to set a script up so it will change a listing back to regular after 90 days

 

 

 

 

 

 

Link to comment
Share on other sites

oh ic it's because i did add a format  date("m.d.y") just had  date() so it was showing in the database as 00-00-0000 =) lol

 

Any idea of how I would go about counting 30 days from the date("m.d.y")??

Want to set a script up so it will change a listing back to regular after 90 days

 

Still showing up as 00-00-000 in database any ideas

 

$date = DATE("m.d.y");
$insetDate = "INSERT INTO sit_details_tmp (rDate) VALUES ('$date')"; 

 

works fine on one script but when added to my other page doesn't work.

Link to comment
Share on other sites

Got that working... Grrrrrrr stupid little issues.

Anyways my biggest issues is counting from date('m.d.y') to 90 days from that time.

e.g.

$date = date('m.d.y');

 

if($date == date('m.d.y') + 30){

 

I know this wont work but does anyone know what I can do to make it work.

 

}

 

Thanks!!

Link to comment
Share on other sites

<?php
date_default_timezone_set('America/Los_Angeles'); //Customize this to local time so that your time/days don't get screwed up.

$add = array (
	'seconds' => 0, //Number of seconds to add.
	'minutes' => 0, //Number of minutes to add.
	'hours' =>   0, //Number of hours to add.
	'days' =>   90  //Number of days to add.
	);

$today = array (
	'd' => date('j'), //Current day.
	'm' => date('n'), //Current month.
	'y' => date('Y')  //Current year.
	);

$currentDay = mktime(0, 0, 0, $today['m'], $today['d'], $today['y']); //Generates the start of today, in unix time.
$futureDay = $add['seconds'] + ($add['minutes'] * 60) + ($add['hours'] * 3600) + ($add['days'] * 86400) + $currentDay; //A bit of magic.


print($futureDay); //$futureDay is now the unix timestamp of the day/time in the future.
print('<br />');
print(date('l - F jS, Y')); //$futureDay can be formatted however you'd like using date(). Consult php.net/date for more ways to customize.
?>

 

I just wrote this up... does it do what you'd like? Customize the $add array if you need to.

Link to comment
Share on other sites

does no one like strtotime()????

 

$today=date('m/d/y');
$theFuture=date('m.d.y',strtotime($today.' + 90 days'));
echo $theFuture;

 

if your mysql table field is set to date format then use that format! (Y-m-d) yyyy-mm-dd

$today=date('m/d/y');
$theFuture=date('Y-m-d',strtotime($today.' + 90 days'));
echo $theFuture;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.