Jump to content

datetime search


matfish

Recommended Posts

  • 3 weeks later...
if you're wanting to manipulate with PHP, just use the following for one year from today:
[code]
<?php
// insert this value into the datetime field
$date = date('Y-m-d', strtotime("today + 1 year"));
?>
[/code]

if you'd rather do it with mySQL directly, you can do the following query:
[code]
INSERT INTO tableName (dateCol) VALUES (DATE_ADD(CURDATE(), INTERVAL 1 YEAR));
[/code]

hope this helps
Link to comment
https://forums.phpfreaks.com/topic/17735-datetime-search/#findComment-86438
Share on other sites

[quote author=matfish link=topic=104492.msg428501#msg428501 date=1157469633]
Hi - thank you - Works a treat!

I gather if I wanted to add on months the same would apply?

Much appreciated!
[/quote]

yes, check out the INTERVAL keyword in the mysql manual. you can use it to declare anything from seconds to years to whatever.
Link to comment
https://forums.phpfreaks.com/topic/17735-datetime-search/#findComment-86455
Share on other sites

[quote author=matfish link=topic=104492.msg428516#msg428516 date=1157470287]
how about if I was using the php manipulation way?
[/quote]

same idea. read up in the manual on strtotime(). it will handle practically any human readable date format or interval and calculate the differences.

good luck
Link to comment
https://forums.phpfreaks.com/topic/17735-datetime-search/#findComment-86492
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

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.