datetime

Incorrect Date in Java

I use next code to print current time Calendar cal = Calendar.getInstance(); System.out.println(cal.getTime()); I have Windows XP sp3 istalled. Current time in system tray is 14:30. But this code return 13:30 Why returned time is wrong? ...

Why does AddMilliseconds round the double paramater?

DateTime.Now.AddMilliseconds(1.5); // adds 2 milliseconds What on earth were they thinking here? It strikes me as horrendously bad practice to create a method that takes a double if it doesn't handle fractional values. Why didn't they implement this with a call to AddTicks and handle the fraction properly? Or at least take an int, so i...

MySQL: How to check if a string is a valid DATE, TIME or DATETIME

When I try to put a value into a DATE field which is invalid, MySQL seems to use 0000-00-00 instead. Is there a way I can do this "check" without updating a DATE field? And to do it from for example PHP? Like, is there a way I can query the MySQL server and ask "Hey, is this DATE, TIME or DATETIME valid to you?" Or is there maybe an ev...

Grouping Months of a particular Time span together using DateTime.

public static string TimeLine2(this HtmlHelper helper, string myString2) { StringBuilder myString3 = new StringBuilder(); DateTime start = new DateTime(2010, 1, 1); DateTime end = new DateTime(2011, 12, 12); myString3.Append("<table>"); myString3.Append("<tr>"); for (DateTime date = start; date <= end;...

Java - creating an oracle date field

I have an Oracle Date type to which I need to insert the current date. I am using Java to generate this date but everything I've tried so far yeilds the following error: java.sql.SQLException: ORA-01843: not a valid month Can anyone suggest java code to generate a proper date? Update: The dates in the DB look like 11-DEC-06 SO, I'...

Linq to XML query date intervals

Hi, i am using a large xml file having in the following format: <Sales> <Sale> <Date>04/20/2010</Date> <Time>18:17:29</Time> <Id>P00000001</Id> <Name>Prod Name</Name> <Description>Prod Desc</Description> <Category>Prod Category</Category> <Subcategory>Prod Subcategory</Subcategory> <Size>Prod Size</Si...

Most concise way to convert Julian date (yyyy[day of year]) to SQL datetime

I'm working with an existing database where all dates are stored as integers in the following format: yyyy[3 digit day of year]. For example: 2010-01-01 == 2010001 2010-12-31 == 2010365 I'm using the following SQL to convert to a datetime: DATEADD(d, CAST(SUBSTRING( CAST(NEW_BIZ_OBS_DATE AS VARCHAR), 5, LEN(NEW_BIZ...

String to DateTime in C# to save in SQL server

Hello All: I have an issue while converting "March 16-17" to DateTime and saving it to SQL server. "March 16-17" as it looks, read as March 16 to March 17, which in my case is invalid, but C# DateTime.TryParse() is treating "March 16 -17" as March 16, 2017 which is wrong, and saving the data in SQL server. SQL server treats "March 16-17...

How to maintain precision using DateTime.Now.Ticks in C#

I know that when I use DateTime.Now.Ticks in C# it returns a long value but I need to store it in an int variable and I am confused as to whether or not I can maintain that precision. As of right now I just have a cast int timeStampValue = (int)DateTime.Now.Ticks; This is a project constraint so I understand there is tons of precisio...

Rails: convert UTC DateTime to another time zone

In Ruby/Rails, how do I convert a UTC DateTime to another time zone? ...

C# - A good library to fake Time.Now?

Hi, In order to Unit-Test a feature, I need to fake DateTime.Now. Something like: SupposeNowIs(new DateTime(..)); I can either use a third library that does it, or write my own little class. What do you recommand? Do you know any good library for this purpose? How would you fake time in C#? By changing DateTime.Now? (I suppose it's r...

How can I get UTC equivalents of Today_and_Now() and Today() in Perl?

How can I get UTC equivalents of Today_and_Now() and Today() call results? Can I convert them back to local time? ...

JScript: How to calculate difference between two date-times?

How can I calculate time difference in JScript between two times in milliseconds or seconds? For example, between 2010-04-23 15:03 and 2010-05-30 00:41 ...

SQL Server - Convert date field to UTC

I have recently updated my system to record date/times as UTC as previously they were storing as local time. I now need to convert all the local stored date/times to UTC. I was wondering if there is any built in function, similar to .NET's ConvertTime method? I am trying to avoid having to write a utility app to do this for me. Any su...

How can I get Rails to interpret a text field as a datetime

My database has a datetime field, and I want to be able to create new entries. Obviously the Rails datetime_select helper isn't the most user friendly thing to have in your form. I'd rather have a text field for the datetime (or one for the date, and one for the time) and interpret the inputs like PHP strtotime can. I might just be sea...

MySQL easy question CURDATE()

I want to compare two results one is stored in the first query, and the other is exactly the same as the first, but i want only to recieve data < today "SELECT s.GSP_nom as nom, timestamp, COUNT(s.GSP_nom) as nb_votes, AVG(v.vote+v.prix+v.serviceClient+v.interface+v.interface+v.services)/6 as moy FROM votes_serveur AS v INNER...

Convert a form_tag select_datetime to SQL datetime

Hi I am trying to make a simple search form that uses a startTime and endTime to specify a time range. The db has a datetime field time that is compared against. So far when i try to use params[:startTime] in the controller I get an array of values which wont work with :conditions => ['time < ?', params[:endTime]] Is there a simple sol...

Most idiomatic way to print a time difference in Java?

I'm familiar with printing time difference in milliseconds: long time = System.currentTimeMillis(); //do something that takes some time... long completedIn = System.currentTimeMillis() - time; But, is there a nice way print a complete time in a specified format (eg: HH:MM:SS) either using Apache Commons or even the dreaded platform...

Getting minimum - Min() - for DateTime column in a DataTable using LINQ to DataSets?

I need to get the minimum DateTime value of a column in a DataTable. The DataTable is generated dynamically from a CSV file, therefore I don't know the name of that column until runtime. Here is code I've got that doesn't work... private DateTime GetStartDateFromCSV(string inputFile, string date_attr) { EnumerableRowCollection<Data...

begin time and start time query

I have following data and using SQL Server 2005 UserID UserName LogTime LogDate 1 S 9:00 21/5/2010 1 S 10:00 21/5/2010 1 S 11:00 21/5/2010 1 S 12:00 21/5/2010 1 S 14:00 21/5/2010 1 S 17:00 21/5/2010 Need Output as:- 1 S 2...