datetime

DateTime Format like HH:mm 24 Hours without AM/PM

Hi there, I was searching here about converting a string like "16:20" to a DateTime type without losing the format, I said I dont want to add dd/MM/yyy or seconds or AM/PM, because db just accept this format. I tried with Cultures yet Thanks in Advance Added Angel says "I am using C#". ...

Approach to convert from org.joda.time.DateTime to java.util.Calendar

Anyone done this and can share? I see an option or two but want to know what others have accomplished. ...

Why does this unit test fail when testing DateTime equality?

Using NUnit 2.2 on .NET 3.5, the following test fails when using DateTime.Equals. Why? [TestFixture] public class AttributeValueModelTest { public class HasDate { public DateTime? DateValue { get { DateTime value; return DateTime.TryParse(ObjectValue.ToStrin...

If I wanted to work using dates and time going millions of years into the past/future how would I do it?

If I wanted to work using dates and time going millions of years into the past/future how would I do it in C/C++/C#? For example say I was working on an algorithm to see if a comet was going to hit the earth? Are there commercial or open source libraries that do this? Most DateTime values only work for a few years. Unixes will run out...

Validate a DateTime in C#

I doubt I am the only one who has come up with this solution, but if you have a better one please post it here. I simply want to leave this question here so I and others can search it later. I needed to tell whether a valid date had been entered into a text box and this is the code that I came up with. I fire this when focus leaves the...

C# DateTime: What "date" to use when i'm using just the "time"?

i'm using a DateTime in C# to display times. What date portion does everyone use when constructing a time? e.g. the following is not valid: //4:37:58 PM DateTime time = new DateTime(0, 0, 0, 16, 47, 58); because there is no zero-th month or zero-th day. Do i use COM's zero date? //4:37:58 PM DateTime time = new DateTime(1899, 12, 3...

How do I get the UTC time of "midnight" for a given timezone?

The best I can come up with for now is this monstrosity: >>> datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) datetime.datetime(2008, 12, 16, 13, 0) I.e., in ...

Days Unavailable

I need a simple SQL to accomplish the below: Problem: When a petrol bunk runs out of fuel, the admin makes note of the DateTime (RunOutDate) when it ran out of fuel and notes also the DateTime (ResupplyDate) when the fuel supply was back on. I need to create a report on how many days the bunk ran out of fuel. eg. 1/1/1 10:10 to 1/1/...

A respectable PHP Datetime parser.

. echo date('r',strtotime("16 Dec, 2010")); //Tue, 16 Dec 2008 20:10:00 +0530 echo date('r',strtotime("16 Dec 2010")); //Sat, 16 Jan 2010 00:00:00 +0530 That's just wrong... Either it should fail or it should parse correctly. Do you know any robust natural language date/time parser in php? How do you parse natural language date ti...

How do you compare DateTime objects using a specified tolerance in C#?

By default C# compares DateTime objects to the 100ns tick. However, my database returns DateTime values to the nearest millisecond. What's the best way to compare two DateTime objects in C# using a specified tolerance? Edit: I'm dealing with a truncation issue, not a rounding issue. As Joe points out below, a rounding issue would introd...

Somewhat strange .NET error involving datetime

I am getting this error on a remote server, but the same code executes fine locally. Please refrain from saying it sucks, or giving me your rant on dynamic sql, I didn't write it, just trying to figure out why it's throwing an exception. The highlighted error is line 56. Protected Sub drpDateRange_SelectedIndexChanged(ByVal sender As Ob...

Illegal Date strings in Java

How do I get a DateFormat of some sort to throw an exception if I try to parse an illegal date? If I parse a date like "99.99.9999" with a SimpleDateFormat with the pattern "dd.MM.yyyy", no exception is thrown, but this is clearly not a valid date. ...

C# How do I convert ticks to minutes?

I have a ticks value of 28000000000 which should be 480 minutes but how can I be sure? How do I convert a ticks value to minutes? Thanks ...

Show HH:mm 24H format in TemplateField using text property

Hi there, im trying to show a 24 hours format using this line: Text='<%# Bind("Appointment", "{HH:mm}") So how it'll be formated for showing for example 16:40 instead 4:40 ? thanks in advance ...

Weekly Schedules - How can you store this in a database?

Currently, I'm working on a project to manage maintenance windows on a database of servers, etc. Basically, I only need to be accurate down to the hour, but allow for them to be set to allow, or disallow, for each day of the week. I've had a few ideas on how to do this, but since I work by myself, I'm not wanting to commit to anything w...

Simplest method to determine if the current time is AM or PM?

What is the best method to determine if the current time is AM or PM using VB.NET? Currently I'm using If Date.Today.ToString.Contains("AM") but I'm sure there is a better method. Good <%If Date.Today.ToString.Contains("AM") Then Response.Write("Morning") Else Response.Write("Afternoon")%> ...

MySQL DATETIME question

I have a DATETIME field. I would like to select all the records that have been updated in the last week. Right now I'm using this query: SELECT SUM(mins_spent) as time_sum FROM todos WHERE lastUpdate >= '2008-12-22' AND lastUpdate <='2008-12-28' But the results i get seem to be different depending on time of the day, e.g on 7 PM I mi...

MySQL schedule conflicts

Hey, I stumbled upon this site looking for solutions for event overlaps in mySQL tables. I was SO impressed with the solution (which is helping already) I thought I'd see if I could get some more help... Okay, so Joe want's to swap shifts with someone at work. He has a court date. He goes to the shift swap form and it pull up this week'...

In Python, how do I find the date of the first Monday of a given week?

If I have a certain week number (eg 51) and a given year (eg 2008), how do I find the date of the first Monday of that same week? Many thanks ...

Custom date format in XML-Schema

I am creating an xml schema, and I want to support a custom date format: Thu Dec 11 14:17:20 2008 Currently I'm using the following pattern type: <xs:simpleType name="Date_Type"> <xs:restriction base="xs:token"> <xs:pattern value="(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|June|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{2}:[0...