datetime

Change today's date, advancing one month and setting the systemtime

I would like a code sample for a function that takes a tDateTime and an integer as input and sets the system time using setlocaltime after advancing that tDateTime by (int) months. The time should stay the same. pseudo code example SetNewTime(NOW,2); The issues I'm running into are rather frustrating. I cannot use incmonth or simila...

How to display DateTime with an abbreviated Time Zone?

I am aware of the System.TimeZone class as well as the many uses of the DateTime.ToString() method. What I haven't been able to find is a way to convert a DateTime to a string that, in addition to the time and date info, contains the three-letter Time Zone abbreviation (in fact, much the same way StackOverflow's tooltips for relative ti...

VB6 Date Datatype: Precision and formatting

Guys, Does anyone know 1) how precise the vb6 Date date type is (by way of fractions of a second) and how to format it to show fractions of a second. I'm revisiting vb6 after many years absence, and for the life of me can't remember. The things I used to know . . . Thanks P.S. I considered putting a "memory-leak" tag on this, beca...

How do I use DateTime.TryParse with a Nullable<DateTime>?

I want to use the DateTime.TryParse method to get the datetime value of a string into a Nullable. But when I try this: DateTime? d; bool success = DateTime.TryParse("some date text", out (DateTime)d); the compiler tells me "'out' argument is not classified as a variable". Not sure what I need to do here. I've also tried: out (Dat...

Why can't .NET parse a date string with a timezone?

.NET throws an exception trying to parse a datetime string in this format: Fri, 10 Oct 2008 00:05:51 CST Convert.ToDateTime("Fri, 10 Oct 2008 00:05:51 CST") results in an exception: The string was not recognized as a valid DateTime. There is a unknown word starting at index 26 Character 26 obviously being the start of "CST" ...

Random date in C#

I'm looking for some succinct C# 3 code to generate a random date between Jan 1 1995 and the current date. I'm thinking some solution that utilizes Enumerable.Range somehow may make this more succinct. ...

Custom Date/Time formatting in SQL Server

I am trying to write a stored procedure which selects columns from a table and adds 2 extra columns to the ResultSet. These 2 extra columns are the result of conversions on a field in the table which is a Datetime field. The Datetime format field has the following format 'YYYY-MM-DD HH:MM:SS.S' The 2 additional fields which should be i...

How to store year in Rails app

I want to just store the year in one of my models. At the moment I just have a database field called year of type date, but it seems to want to take a whole date (yyyy-mm-dd) rather than just a year. What's the best way to store this? In a date field but using some way of just getting it to store the date bit (in which case, how?), or i...

How to get current datetime on windows command line, in a suitable format for using in a filename?

What's a windows command line statement(s) I can use to get the current datetime in a format that I can put into a filename? I want to have a .bat file that zips up a directory into an archive with the current date & time as part of the name, eg "Code_2008-10-14_2257.zip". Is there any easy way I can do this, independent of the regiona...

Oracle database allows invalid time portion of datetime column values under what circumstances?

This case arises in a real-life situation where invalid data was in (and continuing to come into) an Oracle database which is extracted into a data processing system in Focus. Focus would choke and die on some rows with invalid time portions. The Oracle DBA would then go and copy the datetime into the affected column from a good column...

Best way to check when a specified date occurs

Are there any classes in the .NET framework I can use to throw an event if time has caught up with a specified DateTime object? If there isn't, what are the best practices when checking this? Create a new thread constantly checking? A timer (heaven forbid ;) )? ...

Best JavaScript Date Parser & Formatter?

Since I've started to use jQuery, I have been doing a lot more JavaScript development. I have the need to parse different date formats and then to display them into another format. Do you know of any good tool to do this? Which one would you recommend? ...

How to serialize nullable DateTime in a .net web service?

I am trying to pass some Subsonic collections to a client via a web service. When I reference the web service the IDE complains with: Cannot serialize member 'EndDate' of type System.Nullable`1[System.DateTime]. XmlAttribute/XmlText cannot be used to encode complex types. Is there any way of serializing nullable complex types in a .ne...

Set Locale of a SQL Server 2005

By default the SQL Server comes with the Langauge set to "English (United States)", setting the date format to mm/dd/yy instead of the date format I want it in, which is Australian and has a date format such as dd/mm/yy. Is there an option in the Server Management Studio / Configuration tools where I can set the locale of the SQL Server...

sql statement to delete records older than XXX as long as there are more than YY rows

Assume a table with the following columns: pri_id, item_id, comment, date What I want to have is a SQL query that will delete any records, for a specific item_id that are older than a given date, BUT only as long as there are more than 15 rows for that item_id. This will be used to purge out comment records older than 1 year for the i...

Exact time between 2 DateTime?

I would like to know many minutes between 2 dates? Example : Now - tommorow at the exact time would return me 1440. ...

How do you convert YYYY-MM-DDTHH:mm:ss.000Z time format to MM/DD/YYYY time format in Python?

For example, I'm trying to convert 2008-09-26T01:51:42.000Z to 09/26/2008. What's the simplest way of accomplishing this? ...

What's the best format to represent one day?

How to represent the start and end times for one day? Using October 23, 2008 as an example, is it start 2008-10-23 12:00:00 AM and end 2008-10-23 11:59:59 PM? ...

Best way to check whether two dates are the same calendar day in Groovy?

Obviously I could create a Calendar object with the date and use get(DAY) on it, but knowing Groovy, I would guess there is an easier, quicker way I just don't know about? Answer (date1..date2).size() == 1 //true if two dates are on same calendar day ...

SQL Server Active Directory Import Issues with British Summer Time (BST)

I'm using SQL Server ADSI to import data from Active Directory and using the whenChanged field to control if I need to reimport the members of a group. Problem is the date is being returned in GMT and I'm currently in BST. So, did a member change at 9:50 this morning, the AD tools I have say 9:50, but the ADSI query returns 8:50. This...