Questions tagged [date-math]

Questions about performing arithmetic operations on dates and times.

129 questions
0
votes
4 answers

get time difference in hours minutes and seconds

I have two dates, $expiry_time = strtotime('comming from database'); $current_date = strtotime(date('Y-m-d H:i:s')); $time_diff = ($expiry_time-$current_date)/(3600); Here, $time_diff will give me difference in hours. eg. 5.67. But, I want it in…
RNK
  • 5,582
  • 11
  • 65
  • 133
0
votes
3 answers

creating dates+times every 15 minutes does not work

My php code below is supposed to create a list of following dates + times. // your code goes here $maxdays = 1; for($daynumber=0;$daynumber<$maxdays;$daynumber++){ $currentdayval = "+".(string)($daynumber-$maxdays)." days"; $minutes=0; …
Joppo
  • 715
  • 2
  • 12
  • 31
0
votes
1 answer

Returning number of months between two dates

Before you call the firing squad, I realize this question has been asked before. I've looked at what seems like 20 examples on stackoveflow (and other places) and am not understanding why my code won't work. I'm simply trying to use PHP's…
Pete_1
  • 981
  • 3
  • 14
  • 23
0
votes
1 answer

Why is this T-SQL date math not getting the milliseconds correct?

I want to write a T-SQL function that converts a SQL Server datetime value into the number of milliseconds between the input date and 01 JANUARY 1970 00:00:00, the reference date for the javascript Date datatype. create function jDate (@indate…
Tim
  • 8,669
  • 31
  • 105
  • 183
0
votes
2 answers

Get date from the three and a half months ago

I know I can do $threemonthsago = date("Y-m-d", strtotime("-3 month")); echo "$threemonthsago"; However I want to get 3.5 months ago not three months ago. So I tried to do $threemonthsago = date("Y-m-d", strtotime("-3.5 month")); echo…
Jayreis
  • 253
  • 1
  • 7
  • 28
0
votes
1 answer

How to get difference month from 2 date PHP?

i have date $d1='2014-02-01'; $d2='2013-11-01'; i want if i minus $d2 - $d1 = i get difference of month = -3 and if $d1 - $d2 = 3 , Any one can help, sorry for my bad english
Mamen
  • 1,322
  • 5
  • 21
  • 44
0
votes
1 answer

Display a list of past 11 months from current date

I am drawing a bar graph and the values on the x-axis are the months in the last one year period. For example, this is March 2014; so the values on the x-axis range from April 2013 to March 2014 which is the current month. I am using echo…
manlikeangus
  • 421
  • 9
  • 28
0
votes
1 answer

How to add 11 hours to time stored as string

I have a date and timestamp in HL7 format : 201402181659 That represents 2014 02 18 at 16:59 it's offset by +11:00 hours so I need to be able to add 11 hours to the date/time. Any ideas?
Legless
  • 55
  • 3
0
votes
1 answer

Using strtotime() for mathematical operations is not advisable?

While reading the PHP manual for the strtotime() function I got to a "Note" with a very poor explanation - saying this: Note: Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and…
jave.web
  • 13,880
  • 12
  • 91
  • 125
0
votes
2 answers

Mathematical Operation PHP With time

I'm traying to make a mathematical operation with php I have 2 variables, $a2 = $info["Hora_final"]; //END TIME Example-> 15:30:00 $a1 = $info["Hora_inicial"];//FIRST TIME Example-> 10:00:20 But i want this operation (-) minus. $res = $a2 - $a1…
Deimos
  • 269
  • 1
  • 6
  • 17
0
votes
1 answer

How to exact difference between 2 dates in php

I want to find difference between 2 dates in php.But I am not getting exact difference. please help me. The output I must get as "2 years 0 months 0 days". But I am getting as "1 years 12 months and 4 days". where I am…
Sri
  • 15
  • 3
0
votes
1 answer

PHP Add two hours to a date within given hours using function

How would I structure the conditions to add two hours only to dates between 08:30 in the morning until 18:30 of the evening, excluding Saturday and Sunday? In the case that a time near the border (e.g. 17:30 on Tuesday) is given, the left over time…
user1233875
  • 175
  • 4
  • 16
0
votes
1 answer

php DateTime diff method behavior

I have to find the days until an expiration date. I tried to use diff method of DateTime class. $dataexp = 2013-11-06 00:00:00 ; $now = 2013-11-05 13:00:00 ; $dtn = new DateTime('now'); $dte = new DateTime($dataexp); $diff =…
Paolo Rossi
  • 2,490
  • 9
  • 43
  • 70
0
votes
1 answer

PHP DateTime conversion error

I am using this code: //get days $a = date_create($arrive); $d = date_create($leave); //$days = date_diff($d,$a); echo ''; and getting this error: Catchable fatal error: Object of class…
Burning Hippo
  • 787
  • 1
  • 20
  • 47
0
votes
0 answers

In MySQL, somedate - otherdate returns.. what?

I'm just curious because most DBs I ever worked with, when tasked with SOMEDATE - ANOTHERDATE return the difference in days between the two dates MySQL seems to return a number that is.. er.. I've no idea. Sometimes it's the seconds. Sometimes it's…
Caius Jard
  • 72,509
  • 5
  • 49
  • 80
1 2 3
8 9