datetime

How to convert string with unusual format into datetime

I'm using .NET 3.5 and I have a date that comes in as string in the following format: Tue Jan 20 20:47:43 GMT 2009 First question, what is the name of that format? Second question, what's the easiest and clearest way to convert this string into a datetime? I would love to be able to use a .net API/Helper method if possible. Edit: ...

Why can't I create a Date from a string including milliseconds?

In javascript you can create a Date object from a string, like var mydate = new Date('2008/05/10 12:08:20'); console.log(mydate); //=> Sat May 10 2008 12:08:20 GMT+0200 Now try this using milliseconds in the string var mydate = new Date('2008/05/10 12:08:20:551'); // or '2008/05/10 12:08:20.551' console.log(mydate); //=> NaN Just o...

date() returning wrong day although the timestamp is correct!

I have a bizzare problem with php date function. code: $numDays = 8; $date = strtotime('2010-11-06'); for ($i=1; $i<=$numDays; $i++) { $thisDay = date("D, d M Y", $date); print ($thisDay.'<br>'); $date+=86400; // add one day to timestamp } result on my server (local host, windows): Sat, 06 Nov 2010 Sun, 07 Nov 2010 Mon...

Parsing timestamps - do it in MySQL or in PHP?

Let's say you've got a table with a timestamp column, and you want to parse that column into two arrays - $date and $time. Do you, personally: a) query like this DATE(timestamp), TIME(timestamp) , or perhaps even going as far as HOUR(timestamp), MINUTE(timestamp b) grab the timestamp column and parse it out as needed with a loop in PH...

PHP string to Date and Time

I have the following string: 2010-04-08T12:46:43+00:00 I want to convert that to: 8th April 2010 @ 12:46 Is that easy enough? ...

"date_part('epoch', now() at time zone 'UTC')" not the same time as "now() at time zone 'UTC'" in postgresql

I'm writing a web based front end to a database (PHP/Postgresql) in which I need to store various dates/times. The times are meant to be always be entered on the client side in the local time, and displayed in the local time too. For storage purposes, I store all dates/times as integers (UNIX timestamps) and normalised to UTC. One partic...

TimeZoneInfo vs. Olson database

Do TimeZoneInfo and Olson database use identical identificators for time zones? I get timezone id from GeoNames service (which is based on Olson database) and want to retrieve day light saving information for that timezone. ...

MS SQL datetime precision problem

I have a situation where two persons might work on the same order (stored in an MS SQL database) from two different computers. To prevent data loss in the case where one would save his copy of the order first, and then a little later the second would save his copy and overwrite the first, I've added a check against the lastSaved field (d...

JSTL - Format date

Hi! I have a loop that goes through all the news items we have on our site. One of the fields is date ${newsitem.value['Date']}, given in millliseconds. I'd like to display this date in month/day/year format on the webpage. I thought JSTL format tag, <fmt:formatDate>, would help, but I haven't succeeded. Do you know how to do it? ...

What is the fastest way to compare 2 rows in SQL?

I have 2 different databases. Upon changing something in the big one (i don't have access to), i get some rows imported in my databases in a similar HUGE table. I have a job checking for records in this table, and if any, execute a stored procedure, process and delete from table. Performance. (Huge amount of data) I would like to know ...

Sanity Check - Concatenating Date Values - SQL Injection

We currently receive parameters of values as VARCHAR's, and then build a date from them. I am wanting to confirm that the method below would stop the possibility of SQL injection from this statement: select CONVERT(datetime, '2010' + '-' + '02' + '-' + '21' + ' ' + '15:11:38.990') Another note is that the actual parameters being passe...

How to display a DateTime with chosen date parts, but in the order of the FormatProvider?

I want to display the date in the order that the culture provides, but with the elements I want only. The DateTime.Tostring() method has a list of patterns that are very useful but I would like a very small change in it. The CultureInfo used in the following the following code are chosen as example, I don't want to rely on a specific l...

HowTo: obtain culture dateTime format

?string.Format(CultureInfo.GetCultureInfo("en-US"), "{0:d}", now) "4/12/2010" ?string.Format(CultureInfo.GetCultureInfo("fr-FR"), "{0:d}", now) "12/04/2010" I want to write a method: string GetDateFormat(culture) ?GetDateFormat(CultureInfo.GetCultureInfo("en-US")) "M/d/yyyy" ?GetDateFormat(CultureInfo.GetCultureInfo("fr-FR")) "dd/MM...

[Solved] Counting the age of an item in weekdays only

I've been trying to count the age of something in weekdays. I've tried the method detailed in this question, http://stackoverflow.com/questions/883615/given-a-date-range-how-to-calculate-the-number-of-weekends-partially-or-wholly-wi but it doesn't seem to fit my usecase. An item has a created DATETIME in the database, and I need to mark...

Subtracting days in a Calendar object

I need to minus 365 days in a given date (givenDate)- Calendar calendar = Calendar.getInstance(); calendar.setTime(givenDate); calendar.add(Calendar.DATE, -365); Am I right? ...

Storing date and time as epoch vs native datetime format in the database

For most of my tasks I find it much easier to work with date and time in the epoch format: it's trivial to calculate timespan or determine if some event happened before or after another, I don't have to deal with time-zone issues if the data comes from different geographical sources, in case of scripting languages what I usually get...

JAVA UTC to EST from a long UTC timestamp

I'm trying to convert a long timestamp that is UTC to Eastern Standard Time and am totally lost. Any hints would be great! Thanks, R ...

PHP: simplest way to get the date of the month 6 months prior on the first?

So if today was April 12, 2010 it should return October 1, 2009 Some possible solutions I've googled seem overly complex, any suggestions? ...

Yet another date formatting problem :(

Hi folks, I seem to have a date formatting problem every day! I am querying a table and am getting a date back in the format dd/mm/yyyy (as a string btw). Brilliant! thats what I want. But, now I want to convert that string to a date so i can do dim dayNumber as integer = day.DayOfWeek But when I convert it to a date it changes it ...

Getting the 'date' out of a DateTime field in SQL Server

I have a date column where the date is displayed in the format 2009-11-18 10:55:28.370. I just want to get the date (not time) out of that value. How do I do that? ...