Jump to content

datetime


acidglitter

Recommended Posts

$one_week_from_today=mktime(0,0,0,date('m'),date('d')+7,date('y'));

 

This is the jist of it, it assumes that you want the date not the time. This will give you 12:00:00am 7 days from now,

 

for more help check out the date() function and mktime() function. Working with time and dates in PHP can be confusing at first, but once you get the hang of working with the seconds since epoch format, it is really easy to get dates in the past, present, and future. You may want to look at strtotime() as well. This will convert the datetime format in the db to a seconds since epoch format for ya.

 

Enjoy

Link to comment
https://forums.phpfreaks.com/topic/63848-datetime/#findComment-318223
Share on other sites

Try this,

 

<?php
$week=strtotime($row['started'])+mktime(0,0,0,date('m'),date('d')+7,date('y'));

echo date('h:i:s m/d/Y', $week );

?>

 

This should give you something like 3:23:47 8/8/2007 as long as I got the date() formatting right.

 

the datetime field format is something like 1:23:56 5-4-2007 ..... I think

 

In order to use this date/time in an equation you have to convert it to the proper time string, which is where strtotime() comes in.

 

It's late and I am tired so I may have messed this up a little, but I am fairly confident that what I wrote will work.

 

Nate

 

Link to comment
https://forums.phpfreaks.com/topic/63848-datetime/#findComment-318242
Share on other sites

you could do this in teh query itself (mysql date/time support is better than php's)

<?php
$qry = "SELECT date_add(`datefield`, INTERVAL 1 WEEK) as `nxtweek` FROM `table` WHERE {conditions}...";
$qry = mysql_query($qry);

$qry = mysql_fetch_assoc($qry);
$newdate = $qry['nxtweek'];
?>

 

try that and see what happens...

Link to comment
https://forums.phpfreaks.com/topic/63848-datetime/#findComment-318270
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.