Questions tagged [mktime]

mktime is a function that returns the time since the UNIX epoch from a given date and time. Found in C and PHP.

Reference for the C function: https://en.cppreference.com/w/c/chrono/mktime

Reference for the PHP function: https://php.net/manual/en/function.mktime.php

308 questions
125
votes
5 answers

PHP convert date format dd/mm/yyyy => yyyy-mm-dd

I am trying to convert a date from dd/mm/yyyy => yyyy-mm-dd. I have using the mktime() function and other functions but I cannot seem to make it work. I have managed to explode the original date using '/' as the delimiter but I have no success…
Daniel Mabinko
  • 1,351
  • 3
  • 11
  • 10
96
votes
19 answers

Get week number (in the year) from a date PHP

I want to take a date and work out its week number. So far, I have the following. It is returning 24 when it should be 42.
AJFMEDIA
  • 2,093
  • 6
  • 29
  • 52
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
25
votes
4 answers

MKTIME, PHP date/timestamp YYYY-MM-DD

I need to query MySQL for the current date (from PHP) in YYYY-MM-DD format... anyone?
Mikey1980
  • 971
  • 4
  • 15
  • 24
24
votes
1 answer

Curve Fitting to a time series in the format 'datetime'?

Here is my problem: polyfit does not take datetime values, so that I converted datetime with mktime producing the polynomial fit works z4 = polyfit(d, y, 3) p4 = poly1d(z4) For the plot however, I would like the datetime description on the axis…
Corins
  • 241
  • 1
  • 2
  • 3
18
votes
3 answers

mktime and tm_isdst

I saw a lot of different views so thought of asking here. I read man mktime: (A positive or zero value for tm_isdst causes mktime() to presume initially that summer time (for example, Daylight Saving Time) is or is not in effect for the specified…
hari
  • 9,439
  • 27
  • 76
  • 110
15
votes
3 answers

Why does tm_mday start from 1 while all other elements of struct tm start from 0?

While answering another question, I told the OP he needs to initialize his struct tm variable correctly but needs to be careful because he couldn't simply use struct tm mytime; memset(&mytime, 0, sizeof(mytime)); because not all fields of struct tm…
eckes
  • 64,417
  • 29
  • 168
  • 201
15
votes
4 answers

Confusing behaviour of mktime() function : increasing tm_hour count by one

I am executing below code. int main() { struct tm storage={0,0,0,0,0,0,0,0,0}; char *p = NULL; p = (char *)strptime("2012-08-25 12:23:12","%Y-%m-%d %H:%M:%S",&storage); char buff[1024]={0}; strftime(buff,1024,"%Y-%m-%d %H:%M:%S",&storage); cout…
Dhiraj Neve
  • 235
  • 2
  • 4
  • 11
12
votes
1 answer

php time() vs mktime() for current timestamp

Are there any differences between using functions time() and mktime() with default parameters to obtain current timestamp?
Sergey Terehin
  • 153
  • 2
  • 2
  • 9
11
votes
2 answers

What happened on March 16th 1984?

I am trying to figure out what's special about March 16th, 1984. On a virtual machine I am using (nothing special about it), Python (as well as PyPy) crashes when trying to use mktime with what seems to be a perfectly reasonable time struct. $…
Benoît
  • 16,798
  • 8
  • 46
  • 66
10
votes
2 answers

Linux-x64 glibc: Why does Feb 1 come before Jan 31?

When you call mktime(), Feb 1 seems to come before Jan 31. Why is this? Am I doing something wrong or is this a bug in glibc? Here's the code: struct tm tm; time_t tt; memset(&tm, 0, sizeof(tm)); tm.tm_year = 2011; tm.tm_mon = 1; tm.tm_mday =…
Paul A
  • 103
  • 4
9
votes
4 answers

How can I use PHP to list all the dates in a year?

I'm trying to use PHP to create a script that searches all the days between now and one year's time and lists all the dates for Fridays and Saturdays. I was trying to use PHP's date() and mktime() functions but can't think of a way of doing this. Is…
Ben
  • 159
  • 1
  • 3
  • 6
8
votes
3 answers

PHP strtotime() function that accepts a format?

strtotime() in PHP works great if you can provide it with a date format it understands and can convert, but for example you give it a UK date it fails to give the correct unix timestamp. Is there any PHP function, official or unofficial, that can…
Scott
  • 3,967
  • 9
  • 38
  • 56
8
votes
6 answers

In PHP given a month string such as "November" how can I return 11 without using a 12 part switch statement?

I.e. Month Returns January 1 February 2 March 3 April 4 May 5 June 6 July 7 August 8 September 9 October 10 November 11 December 12 I've seen examples using mktime when…
stormist
  • 5,709
  • 12
  • 46
  • 65
1
2 3
20 21