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?
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
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)
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.
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: -
Dim d As DateTime = DateTime.Now
-
-
Dim connectionString As String ="data source=<nameOfDatabaseServer>;initial catalog=<nameOfDatabase>;user id=<databaseUserId>;password=<passwordForDatabaseUser>"
-
Dim dbCon As SqlConnection
-
dbCon = New SqlConnection(connectionString)
-
Dim sqlCom As New SqlCommand
-
-
sqlCom.Connection = dbCon
-
sqlcom.CommandType = CommandType.Text
-
sqlCom.CommandText = "UPDATE my_table SET column1=@value"
-
sqlCom.Parmaeters.Add("@value", SqlDbType.VarChar).Value = d.ToString("YYYYMMDD")
-
-
Try
-
dbCon.Open()
-
sqlcom.ExecuteNonQuery
-
dbCon.Close()
-
Catch ex As Exception
-
MessageBox.Show("A problem occurred: " + ex.Message)
-
End Try
-
-
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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!
|
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.
|
by: ipramod |
last post by:
Hi,
I have an predefined XML format, lets say:
<employee id="1111">
<name></name>
<addr></addr>
<salary></salary>
</employee>
| |
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
|
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...
|
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
|
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.
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |