datetime

DateTime.AddDays or new DateTime

I'm creating a list of a month's worth of dates. I'm wondering what will be more efficient List<DateTime> GetDates(DateTime StartDay) { List<DateTime> dates = new List<DateTime>(); int TotalDays=StartDay.AddMonths(1).AddDays(-1).Day; for (int i=1; i<TotalDays; i++) { dates.Add(new DateTime(StartDay.Year, StartDay.Month, i)); ...

Boost C++ date_time microsec_clock and second_clock

I discovered a strange result in Boost C++ date time library. There is inconsistency between microsec_clock and second_clock, and I don't understand why is that. I am using Windows XP 32-bits My snip of code: using namespace boost::posix_time; ... ptime now = second_clock::universal_time(); std::cout << "Current Time is: "<< to_iso_ext...

Date conversion from db to display

I'm reading a datetime field from mysql db. I'd like to convert it in PHP: from: 2009-05-23 14:46:23 to 05/23/2009 02:46 pm Notice the am/pm conversion. Thanks in advance.. ...

Does configuring django's setting.TIME_ZONE affect datetime.datetime.now()?

The documentation says: http://docs.djangoproject.com/en/dev/ref/settings/#time-zone Note that this is the time zone to which Django will convert all dates/times -- not necessarily the timezone of the server. For example, one server may serve multiple Django-powered sites, each with a separate time-zone setting. Normal...

SQL - Converting 24-hour ("military") time (2145) to "AM/PM time" (9:45 pm)

I have 2 fields I'm working with that are stored as smallint military structured times. Edit I'm running on IBM Informix Dynamic Server Version 10.00.FC9 beg_tm and end_tm Sample values beg_tm 545 end_tm 815 beg_tm 1245 end_tm 1330 Sample output beg_tm 5:45 am end_tm 8:15 am beg_tm 12:45 pm end_tm 1:30 pm I had...

Is there a y2k12 issue analogous to y2k?

This is a bit of a whimsical question inspired in part by the publicity for the movie 2012 but it is one that could have real implications for software systems. (If not in 2012, then definitely in 2038.) There are all sorts of doomsday predictions for the year 2012 and i was wondering if there's a date time/timestamp system out there th...

C# newbie with DateTime variable I want to set to null

I have an output data class with a DateTime variable. I want to clear that to a null value in a loader class but the compiler complains with: Cannot convert null to 'System.Data.Time' because it is a non-nullable value type. I understand that, but if I change the type to DateTime? creating the nullable type wrapper I get: No overload ...

Facebook FBJS UTC

I am pulling in data from a JSON file using FBJS AJAX. On of the values in the json file is a date. The date has a UTC format, Date(1255535021000-0600). However, I am getting an "invalid date" or "NaN" error whatever I do. I have tried the following: new Date(1255535021000-0600), new Date(1255535021000), Date.parse(1255535021000-0600),...

Python datetime subtraction - wrong results?

I must be doing something wrong here, any ideas? >>> (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 It should be getting more than that many seconds. ...

Data type mismatch in criteria expression | Access, OleDb, C#

I read/update data from MS Access using C#. My code is: public static void UpdateLastLogin(int userid, DateTime logintime) ///logintime = DateTime.Now { string sql = @"UPDATE [Customers] SET [LastLogin]=?"; OleDbParameter[] prms = new OleDbParameter[] { new OleDbParameter("@LastLogin",logintime) }; using (DAL dal =...

Setting report to current date

I have a report where it shows meetings and their requirements. However i just want the report to show ONLY today's stuff--not the entire week's worth. I tried setting my group header (i'm grouping by day) to currentdate but yet it still shows me the entire week. I then have to go to the grouping tree and select today's date. Is there...

Get next date from weekday in JavaScript

Dear coding gurus, would you be so kind and tell me if this is possible in JavaScript to return the next date of given weekday (it could be either a number 0-6 or names Sunday-Saturday). Example, if today, on 16-Oct-2009 I passed in: Friday, it would return today's date 16-Oct-2009 Saturday returned 17-Oct-2009 Thursday returned 22-O...

How can I get the current season using .NET? (Summer, Winter, etc...)

Is there a way to, given a date, retrieve the season of the year? For any place on the globe? Is this based on time zone as well as hemisphere? Note that, In the southern hemisphere that summer is still during the warm months. EDIT: To clarify, I am talking about the astronomical seasons. ...

Convert.ToDateTime causes FormatException on afternoon date/time values

We have an application parsing date/time values in the following format: 2009-10-10 09:19:12.124 2009-10-10 12:13:14.852 2009-10-10 13:00:00 2009-10-10 15:23:32.022 One particular server all of the sudden (today) started failing to parse any times 13:00:00 or later. This particular client has five servers and only one has the problem...

Hours corrupted when subtract one day from GregorianCalendar

I use the following code: Calendar calendar = new GregorianCalendar(0,0,0); calendar.set(Calendar.YEAR, 1942); calendar.set(Calendar.MONTH, 3); calendar.set(Calendar.DAY_OF_MONTH, 4); Date date1 = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, -1); Date date2 = calendar.getTime(); System.out.println(date1 + "\n" + date2); ...

How to tell if a timezone observes daylight saving at any time of the year?

In PHP, you can tell if a given date is during the Daylight Savings Time period by using something like this: $isDST = date("I", $myDate); // 1 or 0 The problem is that this only tells you whether that one point in time is in DST. Is there a reliable way to check whether DST is in effect at any time in that timezone? Edit to clarif...

mysql counting results between two datetime

Hey All, Really hope this can be done but I have come across a problem I need to resolve. I have an Inventory booking system for items. Each item gets booked in and out by hours. So some may go in and out within a few hours while others may be days. So in my column I have 2 datetime fields out | in. But I may have multiple items so in...

Delete items older than a day - SQL Server

In a table in my datatase I have a datatime column which stores the time at which the record is added. How can I delete all records which are older than a day when I run a stored procedure (considering the current time) ? ...

mysql adjusting datetime values in the dbase, not in search returns

This must be a ridiculously stupid question, because after numerous searches of the StackOverflow question archives (and elsewhere) I can't find an answer. I recently posted a question about managing date & time data here: http://stackoverflow.com/questions/1587116/mysql-date-storage-query-performance-with-php Following Mike B's advic...

Storing a short date in a DateTime object

I'm trying to store a shortened date (mm/dd/yyyy) into a DateTime object. The following code below is what I am currently trying to do; this includes the time (12:00:00 AM) which I do not want :( DateTime goodDateHolder = Convert.ToDateTime(DateTime.Now.ToShortDateString()); Result will be 10/19/2009 12:00:00 AM ...