473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I convert date format of a column in oledb select statement?

16
Hi,

In my web application I want fetch data from fixed width text file. I am using OLEDB connection for retrieving data. But the problem is the date format is dd/mm/yyyy in text file. Can I change it into mm/dd/yyyy format while fetching. Thanks in advance.
Feb 23 '11 #1
2 12739
GaryTexmo
1,501 Expert 1GB
There's a few ways you can do this... the first way would be to just tokenize your date string and use the pieces accordingly. If your format will always be dd/mm/yyyy separated by slashes like that, you can always do something like this...

Expand|Select|Wrap|Line Numbers
  1. string[] dateComponents = dateTimeString.Split(new char[] { '/' });
  2.  
  3. DateTime theDate;
  4.  
  5. if (dateComponents.Length == 3)
  6. {
  7.   theDate = new DateTime(
  8.     (int)dateComponents[2],
  9.     (int)dateComponents[1],
  10.     (int)dateComponents[0]
  11.   );
  12. }
(Depending on your input, you might want to use int.TryParse there)

For an alternative, have a look at this: http://msdn.microsoft.com/en-us/library/ms131044.aspx

You can use the DateTime.TryParseExact (or DateTime.ParseExact) method to specify the desired format. Here's an example...

Expand|Select|Wrap|Line Numbers
  1. DateTime dt;
  2.  
  3. if (DateTime.TryParseExact("01/02/03", "MM/dd/yy", null, System.Globalization.DateTimeStyles.None, out dt))
  4.     Console.WriteLine("Success -- " + dt.ToString("MMM dd, yyyy"));
  5. else
  6.     Console.WriteLine("Failure");
Feb 23 '11 #2
anoop s
16
Hi I got answer

select FORMAT(Voucherdate,'dd/MM/yyyy')from tbl.

its working.
Feb 24 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ohaya | last post by:
Hi, I'm working with a date string with a format as follows: Sat Dec 25 21:32:59 EST 2004 and I want to compare it to another date string of the format: 7/28/2004
2
by: Annie D via AccessMonster.com | last post by:
Hi, I am using the following SQL statement courtesy of access monster user: 'Terry Kreft ' to convert dates from a text format (20020331 00:00:00) to a recognised date/time format (31/03/2002)....
3
by: skinnybloke | last post by:
Hi - can anybody point me to a tutorial that explains how to format a date field within a SELECT statement. I am trying to create a datafeed into another system. The date field displays as ...
5
by: dubing | last post by:
Hello everyone, There is a field of DATETIME type in our Access 2000 database. PHP is used to query the data and display the query results on the web. Does Access provide any function that can...
1
by: prabhunew2005 | last post by:
I am using postgres,php in web designing. I have to convert date entered in MM-DD-YYYY format to YYYY-MM-DD format. I have to use resulting date format in my search sql. I used todate method. But i...
0
by: Swati Gunda | last post by:
Hello, I am working on C#. I want to convert system date which is by default in mm/dd/yyyy format into dd/mm/yyyy format. If you know the solution then plz reply me immediately. Thanks Swati
2
by: ManickavasagamSathiskumar | last post by:
hai I have one text box in asp page it for date entry field(dd/mm/yyyy)format user entered. But when i store in database it will store (mm/dd/yyyy) format how to change in asp.
2
by: Ifoel | last post by:
Hai All Im beginer in Mysql. I have field Date in MySql, with format "dd/mm/yyyy hh:mm:ss". How to Select it and format change like this "yyyy-mm-dd hh:mm:ss"? Date 04/07/2007 21:23:37
4
by: thomasc1020 | last post by:
This is regarding VB.NET 2003. Variable 'Date' is a string and it contains date information in this format: "DEC/05/2007". Now I am trying to convert the format as "2007-12-05". Is it...
3
Chittaranjan
by: Chittaranjan | last post by:
Hi All, I am not sure how to change the date format in PostgreSQL. I have the dates stored in the database as yyyy-mm-dd HH:MM:SS+TimeZone to get the GMT time (Ex: 2008-02-28 14:03:23+05:30). But...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.