onenonly Posted June 10, 2009 Share Posted June 10, 2009 how does php know of comparing dates not numbers with greater than or less than symbol? I really dont know how to code date with php and mysql. What the best way to input a record into the database but post it two days later? should i put in current time plus 48 hours later into the database but how do i increment the time by 48 hours? Link to comment https://forums.phpfreaks.com/topic/161614-using-php-and-date/ Share on other sites More sharing options...
elis Posted June 10, 2009 Share Posted June 10, 2009 <?php $date = date("Y-m-d"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +12 month"); $date = date("Y-m-d",$date); echo $date; //Other examples $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days"); ?> Change information as required Link to comment https://forums.phpfreaks.com/topic/161614-using-php-and-date/#findComment-852803 Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2009 Share Posted June 10, 2009 how does php know of comparing dates not numbers with greater than or less than symbol? When a string or a number is formatted with fields ordered left to right, MSD (Most Sugnificant digit) to LSD (Least Sugnificant Digit), which for a date would be YYYY-MM-DD (which is why database dates are formatted that way), they can be directly compared and sorted. should i put in current time plus 48 hours later into the database but how do i increment the time by 48 hours? You should always put the current date/time into the database (so you both know when it was inserted and in case you need to change exactly how far into the future/past it gets selected) and then form your query to select that data/time when you want it. Link to comment https://forums.phpfreaks.com/topic/161614-using-php-and-date/#findComment-852806 Share on other sites More sharing options...
onenonly Posted June 10, 2009 Author Share Posted June 10, 2009 s how does php know of comparing dates not numbers with greater than or less than symbol? When a string or a number is formatted with fields ordered left to right, MSD (Most Sugnificant digit) to LSD (Least Sugnificant Digit), which for a date would be YYYY-MM-DD (which is why database dates are formatted that way), they can be directly compared and sorted. should i put in current time plus 48 hours later into the database but how do i increment the time by 48 hours? You should always put the current date/time into the database (so you both know when it was inserted and in case you need to change exactly how far into the future/past it gets selected) and then form your query to select that data/time when you want it. so i should put the current time into the database then parse the code the date entered into the database plus 48 hours? if i have the database auto enter the number into the database with the current time how do I break up the datetime to parse it by 48 hours? Link to comment https://forums.phpfreaks.com/topic/161614-using-php-and-date/#findComment-852811 Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2009 Share Posted June 10, 2009 Mysql has a number of date/time functions that you can use in a query to do just about anything. For selecting records some amount of time into the past/future you would use either the DATE_ADD or DATE_SUB functions - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-add Do you have a specific example of what you are entering into the database and an example of how you want to retrieve it? Are you entering current dates and want to display them until they are 48 hours old (i.e. news stories) or are you entering future dates and want to display them when you are within 48 hours of the date (i.e. calendar events?) or some mix? Link to comment https://forums.phpfreaks.com/topic/161614-using-php-and-date/#findComment-852815 Share on other sites More sharing options...
onenonly Posted June 10, 2009 Author Share Posted June 10, 2009 Mysql has a number of date/time functions that you can use in a query to do just about anything. For selecting records some amount of time into the past/future you would use either the DATE_ADD or DATE_SUB functions - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-add Do you have a specific example of what you are entering into the database and an example of how you want to retrieve it? Are you entering current dates and want to display them until they are 48 hours old (i.e. news stories) or are you entering future dates and want to display them when you are within 48 hours of the date (i.e. calendar events?) or some mix? All i want is when i insert something into the database I want it to be displayed 48 hours later what is the best way of doing this? $a = (current + 48 hours) $b = (current time) should insert the $a into the database and when $b < $a display it or should I insert the $bb into the database and display the code only if ($bb + 48 hours) > $b also should I parse date into mysql code or keep it php date so its eaier to handle? Link to comment https://forums.phpfreaks.com/topic/161614-using-php-and-date/#findComment-852821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.