473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change MMDDYYYY to European format YYYYMMDD

12 New Member
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 2683
Frinavale
9,735 Recognized Expert Moderator Expert
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.ToStri ng() 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 Recognized Expert Top Contributor
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
conerlysduck
12 New Member
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 Recognized Expert Moderator Expert
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 Recognized Expert Moderator Expert
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
3021
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 looking at is to import a CSV file into a table (using Load data infile .... command) where dates are stored in mm/dd/yyyy format and can
4
15918
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 control characters (ie rtf format string) ??? I only need a few formating string; font-weight, font-size, color, and font face
4
16608
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 convert it to this format: m/d/yy. Cheers!
5
2293
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 example) through whole data range? No VBA. Thanks.
1
1718
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
15545
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
6249
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 YYYY-MM-DD. Never mind my asp.net application, even in the Management Studio, SQL Server doesn't seem to accept the following query: SELECT * FROM (table) WHERE (table).(date) = '2008-1-30' It returns the following error: De conversie van...
4
3059
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 taking as a number Thanks Nani
0
1081
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
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
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
10257
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...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
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.