PHP: How to check if a date is today, yesterday or tomorrow

I would like to check, if a date is today, tomorrow, yesterday or else. But my code doesn’t work. Code: $timestamp = “2014.09.02T13:34”; $date = date(“d.m.Y H:i”); $match_date = date(‘d.m.Y H:i’, strtotime($timestamp)); if($date == $match_date) { //Today } elseif(strtotime(“-1 day”, $date) == $match_date) { //Yesterday } elseif(strtotime(“+1 day”, $date) == $match_date) { //Tomorrow } else … Read more

Converting date between DD/MM/YYYY and YYYY-MM-DD?

Using a Python script, I need to read a CVS file where dates are formated as DD/MM/YYYY, and convert them to YYYY-MM-DD before saving this into a SQLite database. This almost works, but fails because I don’t provide time: from datetime import datetime lastconnection = datetime.strptime(“21/12/2008”, “%Y-%m-%d”) #ValueError: time data did not match format: data=21/12/2008 … Read more

Setting timezone to UTC (0) in PHP

Why does this work? date_default_timezone_set(‘Australia/Currie’); But this doesn’t seem to take any effect at all? date_default_timezone_set(‘UTC’); This value doesn’t change when setting the timezone to UTC: echo date(‘Y-m-d H:i:s’, time()); I’m using php 5.2.13, and the timezone of my server is: $server_tz = date_default_timezone_get(); echo $server_tz; //outputs ‘America/Guayaquil’ This is the original code: echo time() … Read more

How to subtract years?

I have a date in R, e.g.: dt = as.Date(‘2010/03/17’) I would like to subtract 2 years from this date, without worrying about leap years and such issues, getting as.Date(‘2010-03-17’). How would I do that? Answer With lubridate library(lubridate) ymd(“2010/03/17”) – years(2) AttributionSource : Link , Question Author : gt6989b , Answer Author : hadley

How do I select between the 1st day of the current month and current day in MySQL?

I need to select data from MySQL database between the 1st day of the current month and current day. select*from table_name where date between “1st day of current month” and “current day” Can someone provide working example of this query? Answer select * from table_name where (date between DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), interval 30 day), interval 1 day) … Read more

How do I extract Month and Year in a MySQL date and compare them?

How do I extract the month and date from a mySQL date and compare it to another date? I found this MONTH() but it only gets the month. I looking for month and year. Answer in Mysql Doku: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_extract SELECT EXTRACT( YEAR_MONTH FROM `date` ) FROM `Table` WHERE Condition = ‘Condition’; AttributionSource : Link , … Read more