473,387 Members | 1,569 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,387 software developers and data experts.

Change MMDDYYYY to European format YYYYMMDD

Hello,

I am trying to change MMDDYYYY to European format YYYYMMDD. I have this in my query:

"20" & Right([TABLE]![DATE],2) & Mid([TABLE]![DATE],3,2) & Left([TABLE]![DATE],2)

which gives me YYYYDDMM. Does anyone know to get the DD and MM switched so it reads YYYYMMDD?
Oct 11 '11 #1
5 2666
Frinavale
9,735 Expert Mod 8TB
When you retrieve a Date from a Database it will be a .NET DateTime Type. You can then use it's ToString method to format the date however you want. In your case you want it formatted as "YYYYMMDD" so you would provide that to the ToString method.


The default pattern that the DateTime.ToString() will returns is based on the user's cultural settings. This is set in the operating system. So if the user has a setting that follows the US date format it will return "MMDDYYYY" but if their cultural setting is French it will return "DDMMYYYY".....The underlying data for the DateTime is actually stored as a number.

This cultural setting is not only applied to dates. There is a way to over write the cultural setting of the operating system so that your application works in the cultural setting that you are expecting. There's a few ways to do this actually...

But I think that the ToString solution that I mentioned will work for your needs.

-Frinny
Oct 11 '11 #2
kadghar
1,295 Expert 1GB
Try assigning your table value to a date variable. Then write it down as you wish:

date1.year & date1.month & date1.day

you can create a function to assure the month and the day will be 2 digits even if they are <10, e.g. iff(a<10, "0" & a, a)
Oct 11 '11 #3
Thank you for your response, but I do not understand the ToString solution that you are referring to. I need to know how to put it in an update query if you can. Thank you.
Oct 11 '11 #4
Frinavale
9,735 Expert Mod 8TB
Is the column that you're using to store the date a "Date" type or is it a "VarChar" type?

If it's a "VarChar" type then you can call the ToString on the DateTime type to store the desired string into the database.

For example, if your column is a varchar then this will work:
Expand|Select|Wrap|Line Numbers
  1. Dim d As DateTime = DateTime.Now
  2.  
  3. Dim connectionString As String ="data source=<nameOfDatabaseServer>;initial catalog=<nameOfDatabase>;user id=<databaseUserId>;password=<passwordForDatabaseUser>"
  4. Dim dbCon As SqlConnection
  5. dbCon = New SqlConnection(connectionString) 
  6. Dim sqlCom As New SqlCommand 
  7.  
  8. sqlCom.Connection = dbCon
  9. sqlcom.CommandType = CommandType.Text
  10. sqlCom.CommandText = "UPDATE my_table SET column1=@value"
  11. sqlCom.Parmaeters.Add("@value", SqlDbType.VarChar).Value = d.ToString("YYYYMMDD")
  12.  
  13. Try
  14.   dbCon.Open()
  15.   sqlcom.ExecuteNonQuery
  16.   dbCon.Close()
  17. Catch ex As Exception
  18.   MessageBox.Show("A problem occurred: " + ex.Message)
  19. End Try 
  20.  
  21.  
Now, if the column storing the date is not a "VarChar" and it is a "Date" type (as it should be) then this technique will not work because you shouldn't be passing a string into the database for the update command: you should be passing a Date into the database for the update command. The database will then store the Date in the column and it will format the date the way that it's configured to format dates.

-Frinny
Oct 11 '11 #5
Frinavale
9,735 Expert Mod 8TB
So upon perusing the forums here on bytes I came across an answer (sort of) to your question.

Your question about how to change the format of a date stored in a database isn't a VB.NET question at all!

It's actually a database question.
You need to change the type (or configuration) of date that you are storing in the database through the database management system that you are using.

Like this How to convert a date from yyyy-mm-dd to dd-mm-yyyy in a db2 database.

Hope I'm making sense.

-Frinny
Oct 14 '11 #6

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

Similar topics

0
by: Karam Chand | last post by:
Hello Is there anyway to change the default date format (possibly in a .ini or .cfg file) from YYYY-MM-DD to another format ? (ie, mm/dd/yyyy or any user-defined format). The useage that I'm...
4
by: Du | last post by:
I want to format the text within my richtextbox. However I have large amount of text to change, simply using richtextbox.select and format is not pratical. How do I change text format using...
4
by: Claudia Fong | last post by:
Hi Is there a way to change a date format dd/mm/yyyy to m/d/yy? I have a textBox where the user should put a date, but no matter what format the user input dd/mm/yyyy or m/d/yy, I need to...
5
by: Li Pang | last post by:
I use sql to get the data from a Excel file. It works only when the data within a column have the same data type. I'd like to know how to change the data format for each column (adding "'" for...
1
by: ipramod | last post by:
Hi, I have an predefined XML format, lets say: <employee id="1111"> <name></name> <addr></addr> <salary></salary> </employee>
1
by: =?Utf-8?B?dHZpbg==?= | last post by:
Hi everyone i want to format YYYYMMDD to MM/DD/YYYY by vb.net is there any format function for this process in vb.net thanks for your help
3
by: YSpa | last post by:
Hi, I'm using SQL-Server Express 2005 on Windows XP Prof. and after working properly for some time my asp.net application suddenly gave the error that my DateFormat wasn't accepted while using...
4
by: naaniibabu | last post by:
I have one number i want to convert in to a date format the size of the value is =8 Char 20091212 i ant to conver it in to a date format my sysyem doent understand wether its adate or not its...
0
by: samgov | last post by:
Is it possible to change the date format in MS Projects to display as DD/MM/YY? The format that I am looking for is not available under the "Date Format" options tab.
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.