datetime

DateTime.Now and NullReferenceException

In my business object I have to obtain the current hour (a DateTime with minutes and seconds = 0). I have created a function like this: private DateTime GetCurrentHour() { return DateTime.Today.AddHours(DateTime.Now.Hour); } If I use it in this way var lastHour=GetCurrentHour(); I get a NullReferenceException ???? U...

sort lines in text file, but only use the first N characters

I have a text file with lines like this: 2010-02-18 11:46:46.1287 bla 2010-02-18 11:46:46.1333 foo 2010-02-18 11:46:46.1333 bar 2010-02-18 11:46:46.1467 bla A simple sort would swap lines 2 and 3 (bar comes before foo), but I would like to keep lines (that have the same date/time) in their original order. How can I do this in Python?...

How to convert yyyymmddMilliseconds to datetime in SQL Server?

I got a table with some time data in the format of yyyymmddMilliseconds. For example, 20100218000051234. How to convert this into DateTime type? In SQL Server 2008. ...

How to suppress time part of a .NET DateTime in display if and only if time part = 00:00:00 ?

In an ASP.NET page I have this: <asp:Label ID="MyDateTimeLabel" runat="server" Text='<%# Eval("MyDateTime") %>' /> I'd like to have it formatted like ... Eval("MyDateTime", "{0:d}") ... // Display only the date if and only if the time part of MyDateTime is 00:00:00. Otherwise like this: ... Eval("MyDateTime", "{0:g}") ... //...

How to convert COledatetime to unix time / php time?

How can I convert a COleDateTime::GetCurrentTime() to a unix time stamp or more specifically I want to convert the value so I can use it in PHP with the date() function? ...

Problem converting a GMT date to local time using C#?

We have a Windows Mobile application written in C# (compact framework). Regional setting is set to (English) New Zealand. Time zone is set to GMT+12 New Zealand. We store our dates in GMT/UTC format. We have a date 2010-02-18 18:00:00 in UTC This time in New Zealand is 7:00 am. When we call on a datetime object starttime = starttime...

find item in collection with closest date

if i have a collection of dates and values. I want to get the value that is either: Associated to the date in the collection if it doesn't exist, i want a linear interpolation between two points that are around the point i am looking for ao, here is a simple example. If the collection is: Date Value 1/1/2009 100 1/1/2010 ...

A question about strftime

The question is simple "Say we have an integer 1 <= n <= 12,How to use strftime to display January for '1',February for '2',March for '3' and so on ... ?" ...

java.util.Date vs java.sql.Date

java.util.Date vs java.sql.Date: when to use which and why? ...

Ruby - Changing the date part of a Time instance

I have a Time instance curr_time with the value of Time.now and another String target_date with the value, say, "Apr 17, 2010". How do I get the date part in the variable curr_time change to the value of target_date ? >> curr_time => Sun Feb 21 23:37:27 +0530 2010 >> target_date => "Apr 17, 2010" I want curr_time to change like this:...

Joda Time formats time at 24:xx:xx UTC should be 0:xx:xx UTC

I'm converting from a local time zone to UTC so when we convert 2010-01-03T11:15:58.840+11:00 => Sun, 03 Jan 2010 24:15:58 UTC This is technically correct but I'm having problems with the 24 hour formatting as it does. I have some BlackBerry J2ME code which is having problems parsing this date-time String using HttpDateParser. new Lo...

How do I convert a mySQL DATETIME type to a string for use in Javascript?

I want to display a DATETIME I get from a mySQL database as a String in Javascript. I'm using PHP to put the DATETIME into a variable: $mydatetime. It displays fine on the PHP page, but not in my javascript function. <?php echo $mydatetime --> 2010-04-19 13:00:00 echo "<script language=javascript>myfunction($mydatetime);...

Validate date on the format "yyMMdd" in ASP.NET

I'm trying to write a custom ASP.NET field validator which makes sure the input is a valid date on the format "yyMMdd". How do I do that? ...

DateTime::createFromFormat in PHP < 5.3.0

I'm looking for a function identical to DateTime::createFromFormat but I need it to work in an environment running a version of PHP which is older than v5.3. Basically I need to provide a format, like you'd use with the Date() function, and I then need to parse/validate a string against that format, and return a timestamp if the string i...

Convert .NET Ticks to SQL Server DateTime

Hello all, I am saving in my DB a TimeSpan (from .NET) value as BIGINT in SQL Server (saving the Ticks property). I want to know how to convert this BIGINT value to a DATETIME value in SQL Server (not in .NET). Any ideas? Cheers EDIT: I am using NHibernate to map a TimeSpan property I have, and it persists the Ticks property. I use i...

add number to date field in vb.net

i have 2 fields in the database (sql server 08) Dob = "05/09/1965" license_age = 16 how do i get the number of years this person hs had licence. so basically dim age1 = current year - (dob - license_age) thanks -- thanks for the answers. worked perfectly. another question based on this. how do i find out which year he got his license ba...

add integer to datetime to find out date in vb.net

similiar question to the one asked before by someone, about age and date. I have 2 fields in sql server 2008 DOB = "01/05/1952" licence_age = 16 how do i get the year he go his licence from this information? ...

How can I stop nHibernate from helpfully setting a date value on a non-null object field when the underlying database field value is null?

I read with excitement the first article that popped up in google -- it was exactly my problem. I have an object model with a non-null date field, but the underlying database field was nullable, and had a null value. It was a DateTime. nHibernate set the value to .Net's Date.MinValue, then tried to save it back, yielding an error. Th...

In Rails, how do I convert and print a time to a different time zone?

I have a variable, start_time: (rdb:5) start_time.class ActiveSupport::TimeWithZone (rdb:5) start_time Tue, 23 Feb 2010 14:45:00 EST -05:00 (rdb:5) start_time.in_time_zone(ActiveSupport::TimeZone::ZONES_MAP["Pacific Time (US & Canada)"]).zone "PST" (rdb:5) start_time.in_time_zone(ActiveSupport::TimeZone::ZONES_MAP["Pacific Time (US &...

SQL Query to only exclude data of last 24 hours?

I have the following data: Table Name: NODE NID | Name | Date 001 | One | 1252587739 Date is a unix timestamp. I need a query, whereby I can select only the nodes who's "Date" is older than 24 hours. Something like this: SELECT * FROM NODE WHERE Date < NOW() - SOMETHING Anybody know how to do this? Does the NOW() - SOMETHING part...