django python date time set to midnight

Using datetimes’s “combine” with the time.min and time.max will give both of your datetimes. For example: from datetime import date, datetime, time pub_date = date.today() min_pub_date_time = datetime.combine(pub_date, time.min) max_pub_date_time = datetime.combine(pub_date, time.max) Result with pub_date of 6/5/2013: min_pub_date_time -> datetime.datetime(2013, 6, 5, 0, 0) max_pub_date_time -> datetime.datetime(2013, 6, 5, 23, 59, 59, 999999)

Start and end date of a current month

There you go: public Pair<Date, Date> getDateRange() { Date begining, end; { Calendar calendar = getCalendarForNow(); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); setTimeToBeginningOfDay(calendar); begining = calendar.getTime(); } { Calendar calendar = getCalendarForNow(); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); setTimeToEndofDay(calendar); end = calendar.getTime(); } return Pair.of(begining, end); } private static Calendar getCalendarForNow() { Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(new Date()); return calendar; } private static … Read more

Python datetime – setting fixed hour and minute after using strptime to get day,month,year

Use datetime.replace: from datetime import datetime dt = datetime.strptime(’26 Sep 2012′, ‘%d %b %Y’) newdatetime = dt.replace(hour=11, minute=59) Also worth noting: datetime.replace returns a new copy of the datetime (since datetime is immutable): it is like str.replace in that regard.

How to add 30 minutes to a JavaScript Date object?

Using a Library If you are doing a lot of date work, you may want to look into JavaScript date libraries like Datejs or Moment.js. For example, with Moment.js, this is simply: var newDateObj = moment(oldDateObj).add(30, ‘m’).toDate(); Vanilla Javascript This is like chaos’s answer, but in one line: var newDateObj = new Date(oldDateObj.getTime() + diff*60000); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)