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

php mktime() unexpected result

Demo https://3v4l.org/CPmvm Output: 2020-07-03 instead of 2018-03-31 How can i get this resolved? Any help is appreciated.
-1
votes
1 answer

date manipulation PHP

I need to create a date object that will be changed by parameters that i get. If I'll get -7 for days it will take me a week ago. Here is my code. How do I format the date correctly? public function…
matisa
  • 497
  • 3
  • 25
-1
votes
1 answer

PHP Warning: mktime()

This is opencart 1.5.5.1.1 - Have this errors: PHP Notice: Undefined index: date_added in /home/u546774105/public_html/projects/all-converse/catalog/view/theme/theme1/template/product/category.tpl on line 88 PHP Notice: Undefined offset: 1 in…
-1
votes
1 answer

Get list of months in a particular year with their start date and last date

I want to get a list of months from a particular year when the year is submitted from a form. The months must come with the start date and the last date of the month. $year = $_POST['year']; $current_year = date('Y'); for…
user3315848
  • 81
  • 1
  • 3
  • 13
-1
votes
3 answers

How to get the first Sunday of year in c++?

I tried to get the date of first Sunday in this year int getFristSunday () { time_t rawtime; struct tm * timeinfo; time( &rawtime ); timeinfo = localtime( &rawtime ); timeinfo->tm_mon = 0; timeinfo->tm_wday = 0; mktime(…
-1
votes
2 answers

mktime having problems with certain years?

I am having a problem with years in mktime(). Every time I pass a year lower than 1970 into my struct tm and then run the mktime() function to convert my structure, it fails (returns -1). Does anyone have any idea why and if I can make this work…
Daeto
  • 440
  • 1
  • 6
  • 19
-1
votes
2 answers

c mktime returns wrong values for wday and yday

I've been trying to use mktime to get which day of the week it is for whatever date I use. But it keeps returning wrong values for wday and yday. I don't care about yday but I'm not sure what the problem. Ive looked over the code multiple times,…
Jason White
  • 666
  • 4
  • 10
  • 23
-1
votes
1 answer

Why does difftime() result in different result when using mktime handling pointer and non-pointer?

I try to use difftime(time_t end, time_t mktime(start) ) to calculate the difference between two different time in two different ways. Just for curiosity!And I found it results in different results, failure and success. I don't know why it…
Alex Lee
  • 161
  • 2
  • 8
-1
votes
2 answers

Convert date to timestap in PHP

I have tried various answers that I found in SO but still I can't manage to make a date into timestamp and I always get a wrong result. I have tried: $date = $this->loadTemplate('element'); //2014-02-27 15:03:00 list($year, $month, $day, $hour,…
otinanai
  • 3,987
  • 3
  • 25
  • 43
-1
votes
3 answers

PHP mktime hell

I have a function that calculate the days difference between two dates: function daysBetweenDates($startDate, $endDate) { list($year1, $month1, $day1) = explode('-', $startDate); list($year2, $month2, $day2) = explode('-', $endDate); $f =…
MurifoX
  • 14,991
  • 3
  • 36
  • 60
-1
votes
3 answers

Why doesn't mktime() work with double digits when a single digit is sufficient?

I'm fairly new to PHP, so forgive me if this is a stupid question. I tried to run mktime() on my site and, because I'm still getting familiar with the syntax, ran something like this: echo date('h:i:s M-d-Y', mktime(12, 00, 00, 12, 08, 2013)…
jimchristie
  • 215
  • 1
  • 11
-1
votes
1 answer

How to fetch the correct date from UNIX timestamp in PHP?

I'm taking two dates from form into mm/dd/yyyy format. Now I'm converting these two dates into equivalent UNIX timestamp value and create a SQL query to fetch the records from the database falling into this range. The small code snippett for this is…
PHPLover
  • 1
  • 51
  • 158
  • 311
-1
votes
1 answer

PHP Number of days for billing cycle with only day of month known

I am trying to calculate number of days in a billing cycle and the number of days left in a billing cycle. I have a value (i.e., 5) which represents the billing date every month (the 5th of every month in this case). I need a way to: a. Calculate…
Jason
  • 1,105
  • 3
  • 16
  • 30
-2
votes
2 answers

mktime() expects at most 6 parameters, 7 given in

The Code: $morningstarts = 9; $eveningends = 22; $dst_change =…
salman ifrahim
  • 371
  • 3
  • 8
-2
votes
1 answer

Using PHP's mktime() on fixed date

So I understand how to use mktime() to create a date based on the current date/time: date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")+1 This creates a date exactly one year from now. But how would I do this…
Daniel Williams
  • 2,195
  • 7
  • 32
  • 53
1 2 3
20
21