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
2
votes
1 answer

ERROR : OverflowError: mktime argument out of range

timestamp = [] for d, t in zip(data['Date'], data['Time']): try: ts = datetime.datetime.strptime(d+' '+t, '%m/%d/%Y %H:%M:%S') timestamp.append(time.mktime(ts.timetuple())) except ValueError: # print('ValueError') …
2
votes
1 answer

mktime or tz database unexpected return for 1941

mktime returns for july 3rd 1941 (00:00:00) and july 4th 1941 (00:00:00) are unexpected. The difference between the two is 82800 seconds, lacking a full hour (3600). The C program diff1941.c (see below) shows the following : $> diff1941 …
2
votes
1 answer

PHP: strtotime vs mktime speed for getting 1 month ago

Which is faster for something simple such as getting the time from one month ago. I can do: strtotime('-1 month'); or mktime(1, 1, 1, date("n") - 1);
2
votes
3 answers

Read time from string as GMT in C++

I am writing current GMT time as string as follow : const std::time_t now = std::time(nullptr); std::stringstream ss; ss << std::put_time(std::gmtime(&now), "%Y-%m-%d %H:%M:%S"); Later I want to do the reverse operation, reading time from the…
Othman Benchekroun
  • 1,998
  • 2
  • 17
  • 36
2
votes
2 answers

Convert multiple dates to Unix time in PHP

Hi I have a few dates coming in random formats: Wed, 16 Mar 2011 15:27:48 +0000 or 2011-03-16T17:42:05+0000 and I need to be able to convert them into Unix time in PHP. I assume I need to use mktime() , ,but how do I format my mktime ? I'm…
BobFlemming
  • 2,040
  • 11
  • 43
  • 59
2
votes
0 answers

Why `mktime()` unexpectedly ignores .tm_isdst for some timezones?

When using mktime(), the .tm_isdst member, when 0 or 1, results in a struct tm --> time_t difference of one 1 hour or the day light savings time shift for many zones such as America/ Los_Angeles. This is as expected and consistent with most…
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
2
votes
2 answers

PHP mktime() for dates pre 1900

So I am working on this system that is sorting dates by decades. I am using make times and I have everything working fine until it hits the year 1900 or below. Afer that everything returns a Dec 24,1964 type date. Can anyone else me why this is…
Devin Dixon
  • 11,553
  • 24
  • 86
  • 167
2
votes
3 answers

how to convert struct tm to time_t in c++

the given function is a part of a class which is used to handle date and time.the file i parse needs to convert the given string data to time_t yet mktime does not work. why? struct tm DateTimeUtils::makeTime(string arrTime)//accepts in…
tanvi rustagi
  • 21
  • 1
  • 2
2
votes
1 answer

Why does mktime return -1 in Awk?

I have file with below data # date format in file is (YYYY MM DD HH MM SS) file_create_date file_execute_date file_name "2017 10 10 12 24 30" , "2017 10 11 09 23 00" ,…
2
votes
1 answer

mktime() gives different results than Howard Hinnant's date library (std::chrono based)

I am using Howard Hinnant's date C++ library (https://howardhinnant.github.io/date/date.html), but I have some confusions using it. Below is a program where I use this library to print the year-month-day of the 3rd Friday of Nov 2017. The…
Work Only
  • 23
  • 2
2
votes
4 answers

Get first day of current week - x

I need to get the first day of the week (Monday), 8 weeks back from today, where 8 is a variable. What's the best way to do that in PHP?
B.1988
  • 35
  • 2
  • 7
2
votes
4 answers

How to convert mktime() to a numeric date?

I have used mktime() function in my code. And it prints this: Feb-12-1998. I wanna convert this something like that: 02-12-1998. But in my language it has to be 12-02-1998. Im kind of confused. Some help would be…
FurkOk
  • 67
  • 10
2
votes
1 answer

mktime returns incorrect value

I'de like to use mktime on a microcontroller (or at least use 32-bit wide timestamps). I added the needed files from avr libc source files (in Atmel Studio 7, time functions aren't available), didn't change the algoritms. But for 2016. 06. 08.…
klenium
  • 2,468
  • 2
  • 24
  • 47
2
votes
1 answer

Why is there a one hour difference between two time_t values when converting to tm struct and back?

When I execute the following code: #include #include int main(int argc, char *argv[]) { time_t rawtime = 0; time_t secs; struct tm* timeinfo = gmtime(&rawtime); printf("rawtime : %s\n", asctime(timeinfo)); secs =…
AB71E5
  • 123
  • 1
  • 4
2
votes
1 answer

how to make time.mktime work consistently with datetime.fromtimestamp?

I am expecting the following code will return 0 but I get -3600, could someone explains why? and how to fix it? thanks import datetime import time ts = time.mktime(time.gmtime(0)) print…
John
  • 2,107
  • 3
  • 22
  • 39