473,761 Members | 4,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

16 New Member
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 12893
GaryTexmo
1,501 Recognized Expert Top Contributor
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.TryPar seExact (or DateTime.ParseE xact) 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 New Member
Hi I got answer

select FORMAT(Voucherd ate,'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
4068
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
5206
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). SELECT END_DTTM, Left(,4) AS END_DTTM_year, Mid(,5,2) AS END_DTTM_month,
3
1418
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 "2005/09/24 12:33" within the results from my SELECT statement and I want it to display either display "20050924" or the reverse "24092005" and to drop the time - not sure which one yet.
5
61222
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 convert DATETIME field into a more user friendly format directly in query? I can do the following in MySQL. How should it be done in Access? SELECT DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');
1
11433
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 did not get correct answer. Can you give me a solution for this? (37 minutes ago )
0
1632
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
3934
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
1266
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
4528
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 possible to convert the arrangement using 'Format' method? If so, please educate me how I can do such operation. Thank you!
3
24436
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 I want these dates to be shown in the following format: dd/mm/yyyy HH:MM:SS TimeZone (Ex: 28/02/2008 14:03:23 IST)So now while I am trying to fetch the dates from the database I am using to_char() as below: to_char(field_name, 'DD/MM/YYYY...
0
9538
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10123
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5241
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3889
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.