Questions tagged [strtotime]

PHP function for parsing about any English textual datetime description into a Unix timestamp

Samples

strtotime('first day of this month');
strtotime('last day of this month');
strtotime('-1 month'); # current date -1 month
1308 questions
36
votes
8 answers

PHP date showing '1970-01-01 ' after conversion

I have a form in which date format is dd/mm/yyyy . For searching database , I hanverted the date format to yyyy-mm-dd . But when I echo it, it showing 1970-01-01 . The PHP code is below: $date1 = $_REQUEST['date']; echo date('Y-m-d',…
AssamGuy
  • 1,571
  • 10
  • 30
  • 43
33
votes
3 answers

How to convert week number and year into unix timestamp?

I'm trying to group together dates into a week number and year, and then I want to convert that week number back into a unix timestamp. How can I go about doing this?
blacktie24
  • 4,985
  • 6
  • 41
  • 52
31
votes
8 answers

Finding days between 2 unix timestamps in php

Hay, i have a database holding events. There are 2 fields 'start' and 'end', these contain timestamps. When an admin enters these dates, they only have the ability to set the day,month,year. So we are only dealing with stamps containing…
dotty
  • 40,405
  • 66
  • 150
  • 195
28
votes
1 answer

date() method, "A non well formed numeric value encountered" does not want to format a date passed in $_POST

I unfortunately can't use DateTime() as the server this project is on is running PHP v.5.2. the line in question: $aptnDate2 = date('Y-m-d', $_POST['nextAppointmentDate']); throws the following error: Notice: A non well formed numeric value…
tdc
  • 5,174
  • 12
  • 53
  • 102
27
votes
4 answers

DateTime class vs. native PHP date-functions

The DateTime class sure has some handy methods and seems overall superior to the native PHP date functions like strtotime, mktime and strftime (and more). But is there any drawback or a reason why I shouldn't use it ? The only reason I can think of…
Anonymous
  • 3,679
  • 6
  • 29
  • 40
27
votes
9 answers

strtotime With Different Languages?

Does strtotime only work in the default language on the server? The below code should resolve to august 11, 2005, however it uses the french "aout" instead of the english "aug". Any ideas how to handle this?
Cory Dee
  • 2,858
  • 6
  • 40
  • 55
27
votes
4 answers

Current date + 2 months

I wrote this piece of code in order to display the current date + 2 months : It does not seem…
morgi
  • 1,005
  • 3
  • 17
  • 24
26
votes
5 answers

PHP's strtotime() in Java

strtotime() in PHP can do the following transformations: Inputs: strtotime(’2004-02-12T15:19:21+00:00′); strtotime(’Thu, 21 Dec 2000 16:01:07 +0200′); strtotime(’Monday, January 1st’); strtotime(’tomorrow’); strtotime(’-1 week 2 days 4 hours 2…
User1
  • 39,458
  • 69
  • 187
  • 265
26
votes
3 answers

How to get timestamp of current month, first day of month, zero hour

I am trying to get the timestamp of the first day of the month at 00:00:00. For example, the timestamp of Jan 01 2012 00:00:00 I'm doing this: $test_month = time(); // Seconds $test_month = date('M', $test_month); // This month $test_month =…
MultiDev
  • 10,389
  • 24
  • 81
  • 148
25
votes
7 answers

PHP strtotime +1 month adding an extra month

I have a simple variable that adds one month to today: $endOfCycle = date("Y-m", strtotime("+1 month")); Today is January 2013, so I would expect to get back 2013-02 but I'm getting 2013-03 instead. I can't figure out why it's jumping to March.
Jason
  • 1,105
  • 3
  • 16
  • 30
23
votes
2 answers

Convert this string to timestamp PHP

I have this string: "13/10 15:00" and I would like to convert it to timestamp but when I do this: $timestamp = strtotime("13/10 15:00"); It returns an empty value.
user2876368
  • 667
  • 2
  • 6
  • 7
23
votes
3 answers

Adding days to specific day

Many examples are about adding days to this day. But how to do it, if I have different starding day? For example (Does not work): $day='2010-01-23'; // add 7 days to the date above $NewDate= Date('$day', strtotime("+7 days")); echo…
jsk
  • 327
  • 1
  • 4
  • 10
23
votes
7 answers

how to get date for holidays using php

For example the: 3rd Monday of January for Martin Luther King Day 3rd Monday of February for Presidents' Day (Washington's Birthday) Last Sunday of March for Easter Last Monday of May for Memorial Day I am trying to get these dates, so that…
telexper
  • 2,381
  • 8
  • 37
  • 66
22
votes
3 answers

strtotime result makes no sense, php bug?

The following line: echo date('d', strtotime('First Saturday August 2015')); prints 08, which doesn't seem to make any sense because the first occurrence of a day of the week can't be after the 7th. Is it a php bug or a php bug or maybe even a php…
Markus Kottländer
  • 8,228
  • 4
  • 37
  • 61
22
votes
6 answers

How to get closest date compared to an array of dates in PHP

This post almost answered this question for me, but I have a specific need and didn't find what I sought there. This lies right outside my experience; couldn't quite wrap my head around it, so all I really need is a point in the right…
user1881190
1
2
3
87 88