strtotime

how do i display a date by adding a few months to it

左心房为你撑大大i 提交于 2019-12-25 01:53:33
问题 if i have a date 10/10/2009 and i wanted to add strtotime(+# months) to display an expiration date? the 10/10/2009 is a start date which is imputed by the customer and the +# months is how ever many months were added for a specific product to display the expiration date. how would i add the two to find the expiration date? 回答1: This tutorial helped me with exactly this kind of problem recently. $date = "2009-10-10"; $newdate = strtotime ("$date +3 month") ; $newdate = date ( 'Y-m-j' ,

strtotime with variable in wordpress

核能气质少年 提交于 2019-12-24 20:27:23
问题 I've tried to change this code: function filter_where( $where = '' ) { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-365 days')) . "'"; return $where;} add_filter( 'posts_where', 'filter_where' ); into this one: function filter_where( $where = '' ) { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-'.$timestamp.' days')) ."'"; return $where;} add_filter( 'posts_where', 'filter_where' ); You may noticed that I've tried to put variable $timestamp inside strtotime. However

February and strtotime

梦想与她 提交于 2019-12-24 12:46:30
问题 okay? I'm trying to hit a calculation date here, however I am not getting .. What happens is the following: $AtualMenos3 = date("m-d-Y", strtotime("2013-03-31 -3 month")); $AtualMenos2 = date("m-d-Y", strtotime("2013-03-31 -2 month")); $AtualMenos1 = date("m-d-Y", strtotime("2013-03-31 -1 month")); $AtualMes = date("m-d-Y", strtotime("2013-03-31")); The correct should be: 03-31-2013 02-28-2013 01-31-2013 12-31-2012 However, this php calculating the date wrong, because when month is February

如何使用PHP计算两个日期之间的差异?

雨燕双飞 提交于 2019-12-23 20:02:37
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我有两个日期格式: Start Date: 2007-03-24 End Date: 2009-06-26 现在,我需要以以下形式查找这两者之间的区别: 2 years, 3 months and 2 days 如何在PHP中做到这一点? #1楼 前段时间,我编写了 format_date 函数,因为它为 您 提供 了如何选择日期的许多选项 : function format_date($date, $type, $seperator="-") { if($date) { $day = date("j", strtotime($date)); $month = date("n", strtotime($date)); $year = date("Y", strtotime($date)); $hour = date("H", strtotime($date)); $min = date("i", strtotime($date)); $sec = date("s", strtotime($date)); switch($type) { case 0: $date = date("Y".$seperator."m".$seperator."d",mktime($hour, $min, $sec, $month,

PHP strtotime() outputs nothing

冷暖自知 提交于 2019-12-23 12:19:04
问题 Here is my PHP code: echo '<br />1. '.$w_time_no; echo '<br />2. '.strtotime($w_time_no); echo '<br />3. '.date('G:i', strtotime($w_time_no)); That's what I get: 1. 0000-00-00 22:00:00 2. 3. 2:00 Why strtotime() outputs nothing by itself? Is there something wrong with server settings? Server: Apache/2.2.11 (Win32), PHP 5.2.10, MySQL client version: 5.0.51a. 回答1: strtotime doesn't "output" anything, btw : it returns false in case of an error ; see the manual : Return Values Returns a timestamp

How to get date from week number & day number and year?

ⅰ亾dé卋堺 提交于 2019-12-23 06:04:28
问题 I'm trying to get the date from the week number, day number and year. For eg: week number = 52 day number = 4 (of week 52) year = 2013 In this case, the date should be 26-12-2013 . How can I do it using PHP? I've already tried with strtotime() , but I'm confused about the formats. Can someone help? 回答1: Make use of setISODate() <?php $gendate = new DateTime(); $gendate->setISODate(2013,52,4); //year , week num , day echo $gendate->format('d-m-Y'); //"prints" 26-12-2013 回答2: Try this code. <

32 hours ago excluding weekends with php

烈酒焚心 提交于 2019-12-22 08:45:04
问题 So I have a script that does multiple checks for 32, 48 and 72 hours ago. Basically I check my database for entries that are at least x hours old. Now this works fine like this: $date = date('Y-m-d H:i:s',strtotime('-32 hours')); $q = "SELECT * FROM `table` WHERE `date` <= '".$date."'"; Now I want this to exclude weekends. I know you can use weekdays within strtotime to get this effect however this doesn't work for hours. For 48 hours it's easy because I can simply do the following: echo date

strtotime('today') returning incorrect time?

最后都变了- 提交于 2019-12-22 03:51:36
问题 I am trying to create a select list starting from the current date of the user. I want it so that it is set to midnight in unix timestamp format. This is all I'm doing: $today = strtotime('today'); echo $today; This is my result: 1333144800 which is: Fri, 30 Mar 2012 22:00:00 GMT according to Epoch Converter (incorrect by a couple hours.) 回答1: If you want strtotime() to return a timestamp relative to UTC (00:00:00 UTC instead of e.g. 00:00:00 UTC+2, if your system is set to a timezone with an

PHP strtotime: Get previous month [duplicate]

和自甴很熟 提交于 2019-12-22 01:37:42
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to get previous month and year relative to today, using strtotime and date? Today is December, 31st but strtotime("-1 months") returns December: echo date("Y-m", strtotime("-1 months")); Same for strtotime("last month") How can I properly return the previous month (November)? Test: http://codepad.viper-7.com/XvMaMB 回答1: strtotime("first day of last month") The first day of is the important part as detailed

Issue with php strtotime function when using ordinal values

眉间皱痕 提交于 2019-12-21 18:04:20
问题 I sometime get unexpected results when using ordinal values with strtotime. For example, why does date("M j", strtotime("second Tuesday February 2011")) result in "Feb 15" (which is actually the third Tuesday in 2011? 回答1: You are missing an 'of'. $ php -r 'echo date("M j", strtotime("second Tuesday February 2011"));' Feb 15 $ php -r 'echo date("M j", strtotime("second Tuesday of February 2011"));' Feb 8 PHP Version: $ php -v PHP 5.3.3 (cli) (built: Aug 22 2010 19:41:55) Copyright (c) 1997