datetime

Parsing exact dates in C# shouldn't force you to create an IFormatProvider

Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific formats) dates in C# should be as easy as DateTime.ParseExact(theDate, "yyyy/MM/dd"); but no, C# forces you to create an IFormatProvider. Is there an app.config friendly way of setting this so I don't need to do this each time? DateTime.ParseExact(t...

Best practices for DateTime serialization in .Net framework 3.5/SQL Server 2008

Some 4 years back, I followed this MSDN article for DateTime usage best practices for building a .Net client on .Net 1.1 and ASMX web services (with SQL 2000 server as the backend). I still remember the serialization issues I had with DateTime and the testing effort it took for servers in different time zones. My questions is this: Is t...

Mono's DateTime Serialization

if you uses Mono Remoting on Linux, what's your work-around for DateTime marshalling incompatibility between Mono and .NET Remoting? i'm using WinForms on Windows using .NET 2.0 runtime, using Remoting on Linux using Mono. i cannot yet use Mono runtime on both ends as Mono's DataGridView isn't yet working. [UPDATE] i used Mono 1.9 wh...

How do I convert local time to UTC in Python?

How do I convert a datetime string in local time to a string in UTC time? I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future. Clarification: For example, if I have "2008-09-17 14:02:00" in my local timezone (+10), I'd like to generate a string with the equivalent UTC time: "2...

Handling and storing elapsed time

I'm having problems deciding on what is the best way is to handle and store time measurements. I have an app that has a textbox that allows the users to input time in either hh:mm:ss or mm:ss format. So I was planning on parsing this string, tokenizing it on the colons and creating TimeSpan (or using TimeSpan.Parse() and just adding a...

Same source code on two machines yield different executable behavior

Here's the scenario: A C# Windows Application project stored in SVN is used to create an executable. Normally, a build server handles the build process and creates builds at regular intervals which are used by testing. In this particular instance I was asked to modify a specific build and create the executable. I'm not entirely sure ...

What's the best way to manipulate Dates and Timestamps in Java?

Every time I need to work with date and/or timstamps in Java I always feel like I'm doing something wrong and spend endless hours trying to find a better way of working with the APIs without having to code my own Date and Time utility classes. Here's a couple of annoying things I just ran into: 0-based months. I realize that best pra...

How would I store a date that can be partial (i.e. just the year, maybe the month too) and output it later with the same specifity?

I want to let users specify a date that may or may not include a day and month (but will have at least the year.) The problem is when it is stored as a datetime in the DB; the missing day/month will be saved as default values and I'll lose the original format and meaning of the date. My idea was to store the real format in a column as a...

What languages do date, time, and calendar operations really well?

This is probably too much to ask, but is there any language that does a really terrific job of representing time and date operations? I'll grant straight away that it's really hard to write a truly great time library. That said, are there any widespread languages that have one? Basically, I want something that handles time and date as...

How do I convert a date/time to epoch time (aka unix time -- seconds since 1970) in Perl?

Given a date/time as an array of (year, month, day, hour, minute, second), how would you convert it to epoch time, i.e., the number of seconds since 1970-01-01 00:00:00 GMT? Bonus question: If given the date/time as a string, how would you first parse it into the (y,m,d,h,m,s) array? ...

Python - easy way to add N seconds to a datetime.time?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example? These obvious ideas don't work: >>> datetime.time(11, 34, 59) + 3 TypeError: unsupported operand type(s) for +: 'datetime.time' and 'int' >>> datetime.time(11, 34, 59) + datetime.timede...

How do I work with quarters (quarterly dates) in ASP.Net using VB.Net 2.0?

I know that Sql Server has some handy built-in quarterly stuff, but what about the .Net native DateTime object? What is the best way to add, subtract, and traverse quarters? Is it a bad thing™ to use the VB-specific DateAdd() function? e.g.: Dim nextQuarter As DateTime = DateAdd(DateInterval.Quarter, 1, DateTime.Now) Edit: Expanding...

What does "DateTime?" mean in C#?

I am reading a .Net book, and in one of the code examples there is a class definition with this field: private DateTime? startdate What does "DateTime?" mean? ...

In C#, given a DateTime object, how do I get a ISO 8601 date in string format?

Given: DateTime.UtcNow How do I get a string which represents the same value in an ISO 8601 compliant format? Note that ISO 8601 defines a number of similar formats: (Wikipedia). The specific format I am looking for is: yyyy-MM-ddTHH:mm:ssZ ...

Converting a year from 4 digit to 2 digit and back again in C#

My credit card processor requires I send a two-digit year from the credit card expiration date. Here is how I a currently processing: I put a DropDownList of the 4-digit year on the page. I validate the expiration date in a DateTime field to be sure that the expiration date being passed to the CC processor isn't expired. I send a two-d...

How do I use timezones with a datetime object in python?

How do I properly represent a different timezone in my timezone? The below example only works because I know that EDT is one hour ahead of me, so I can uncomment the subtraction of myTimeZone() import datetime, re from datetime import tzinfo class myTimeZone(tzinfo): """docstring for myTimeZone""" def utfoffset(self, dt): ...

Simplest way to create a date that is the first day of the month, given another date

In SQL Server what is the simplest/cleanest way to make a datetime representing the first of the month based on another datetime? eg I have a variable or column with 3-Mar-2005 14:23 and I want to get 1-Mar-2005 00:00 (as a datetime, not as varchar) ...

SQL Server 2005 vs. ASP.net datetime format confusion

Hi, I've found a similar question on stack overflow, but it didn't really answer the question I have. I need to make sure that my asp.net application is formatting the date dd/mm/yyyy the same as my SQL Server 2005. How do I verify the date culture (if that's what it's called) of the server matches how I've programmed my app? Are there...

How to parse ISO formatted date in python?

I need to parse strings like that "2008-09-03T20:56:35.450686Z" into the python's datetime? I have found only strptime in the python 2.5 std lib, but it not so convinient. Which is the best way to do that? Update: It seems, that python-dateutil works very well. I have found that solution: d1 = '2008-09-03T20:56:35.450686Z' d2 = date...

Python Date Comparisons

I would like to find out if a particular python datetime object is older than X hours or minutes. I am trying to do something similar to: if (datetime.now() - self.timestamp) > 100 # Where 100 is either seconds or minutes but this obviously gives a type error. So my question is what is the proper way to do date time comparison in py...