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

Why is mktime() changing the year day of my tm struct?

I read in two strings with a Year, the Julian Day (year day), hour, minute, and an observation. I pull the relevant variables out using sscanf: sscanf(tide_str1.c_str(), "%d %d %d %d %Lf", &y1, &j1, &h1, &m1, &obs1); sscanf(tide_str2.c_str(), "%d %d…
RuQu
  • 243
  • 3
  • 4
  • 9
6
votes
4 answers

Get previous month date range

I need help getting the previous months full date range in the following format: Y-m-d I have successfully been able to get "this" months full date range but not the "previous" months full date range. Any help is greatly appreciated!
three3
  • 2,756
  • 14
  • 57
  • 85
6
votes
2 answers

Fast way to transform datetime strings with timezones into UNIX timestamps in C++

I want to convert a huge file containing datetime strings to seconds since UNIX epoch (January 1, 1970) in C++. I need the computation to be very fast because I need to handle large amount of datetimes. So far I've tried two options. The first was…
charitha22
  • 89
  • 9
6
votes
2 answers

PHP mktime and timezone

I'm working on some time related features and I opt to always use UTC times and store time stamps as integers for consistency. However, I noticed that when I use mktime it seems that the currently set time zone has an influence of the return value…
Luke
  • 20,878
  • 35
  • 119
  • 178
6
votes
1 answer

Bug in mktime() on CentOS?

I have been playing with mktime, and I noticed a weird, and inconsistent, behavior. I provide it with a date which is not during DST (daylight saving time), but with tm_isdst is set to 1, what mktime usually does is change tm_isdst to 0, and adjust…
Marcin Zukowski
  • 4,281
  • 1
  • 19
  • 28
5
votes
1 answer

Running C code with mktime inside PHP's exec

I am having a strange problem with PHP and a C script that uses the current time. My program is a little complex, but the problem narrows itself to this: I have this C code which prints the date 1 minute ago, the current date, and the date 1 minute…
nmat
  • 7,430
  • 6
  • 30
  • 43
5
votes
2 answers

Confusing behaviour of mktime on Linux?

I am using the mktime(struct tm*) function in Suse 10. Now, I am noticing some strange behaviour when daylight saving time is enabled. Let's say I have enabled daylight saving time to begin on Sep 15 at 18:10 and the daylight correction is for 30…
Jay
  • 24,173
  • 25
  • 93
  • 141
5
votes
4 answers

Why does mktime give me an hour less?

I would like to see if at 00:00:00 on January 1, 1970 it actually corresponds to 0 seconds, and I wrote the following: #include #include int main(void) { int year = 1970; struct tm t = {0}; t.tm_mday = 1; //…
Roberto Rocco
  • 450
  • 2
  • 11
5
votes
1 answer

PHP convert mktime result to UTC

I am using this code to generate yesterday's beginning of day in PST (aka America/Los_Angeles) time. I can't figure out how to convert the result to UTC. date_default_timezone_set("America/Los_Angeles"); $time1 = date("Y-m-d H:i:s", mktime(0,0,0,…
apadana
  • 13,456
  • 15
  • 82
  • 98
5
votes
3 answers

Ruby convert DD/MM/YYYY string to YYYY,MM,DD

I'm collecting a users input as "DD/MM/YYYY" The aim is to pass into mktime as csv YYYY,MM,DD. puts "Please enter dob in dd/mm/yyyy format;" inp = gets.chomp inp = inp.gsub(" ","") while inp.length != 10 puts "Please use dd/mm/yyyy format" inp…
Barris
  • 969
  • 13
  • 29
5
votes
4 answers

How to calculate time differences in C++ with time_t before the epoch?

What I would like to do with my simple program is to calculate a difference in seconds between two dates. time_t referenceDate; time_t dateNow = time(0); struct tm referenceDateComponent = {0}; referenceDateComponent.tm_hour =…
BEPP1
  • 945
  • 2
  • 11
  • 15
5
votes
1 answer

Convert between date/time and time-stamp without using std library routines

I am trying to implement in C two simple convertors, date/time to time-stamp and vice-versa, without any dependencies on time library routines (such as localtime, mktime, etc, mainly due to the fact that some of them are thread-unsafe). I have…
barak manos
  • 29,648
  • 10
  • 62
  • 114
5
votes
7 answers

Displaying the list of months using mktime for the year 2012

Am am current facing a problem that need a solution ASAP. I am trying to list all months of the current year(2012) by using the following code: for ($m=1; $m<=12; $m++) { $month = date('F', mktime(0,0,0,$m)); echo $month. '
'; …
4
votes
1 answer

awk: mktime returns -1

Can someone help me understand why I get "-1" returned by mktime in the following code. Thanks. #!/usr/local/bin/bash f_name="crap.stat" S_Date="2012-02-10" E_Date="2012-02-13" gawk -F '\t' -v s_date="$S_Date" -v e_date="$E_Date" 'BEGIN {s_time =…
Shuvo Shams
  • 633
  • 4
  • 10
  • 22
4
votes
1 answer

valgrind complaining about __mktime - is that my fault?

For the first time (in my new dev environment) I'm seeing valgrind complain about mktime, but I'm not sure if this is a bug in the libc library, valgrind, or my code. I'll start with the error (below) - is this enough info to explain the…
Michelle Dupuis
  • 337
  • 1
  • 5
  • 20
1
2
3
20 21