i need to convert datetime before insert into database by using this format dd-MM-yyyy
below is my query, i need help, i really new in sql query
the bold word is my date
Dim commandString As String = "INSERT INTO KesalahanDisiplin" & _
"(IdPelajar,NoIc,KategoriKes,SubKes,Jam,Minit,Waktu,TarikhKes,TempatKejadian,PuncaSalahLaku,MaklumIbuBapa,TindakanPenjaga,SiaranMedia,KeteranganKes,PengesahanDisiplin,AduanOleh)" & _
"VALUES(@IdPelajar,@NoIc,@KategoriKes,@SubKes,@Jam,@Minit,@Waktu,@TarikhKes,@TempatKejadian,@PuncaSalahLaku,@MaklumIbuBapa,@TindakanPenjaga,@SiaranMedia,@KeteranganKes,@PengesahanDisiplin,@AduanOleh)"
I suggest you should use default format for date time that is supported in SQL Server, for displaying
to user, you can play with it in any format you like.
I have had problems in managing my own custom format of date in the database, I think you must
declare the field as varchar as SQL server wont allow you to store the date in non-SQL DateTime column format !
And after reading ur post I think u dont care for the time, so the best way is to use SQL Server's own date format
and in your query, you can build like that
As soon as you start talking about formats you are talking about strings. This is relevent when you are displaying a date.
If you are writing to a database table, any discussion about formatting means you are doing something unwise. Either you are trying to put a string into a date field or you are storing dates in a char datatype. While the first might occasionally work,
it's not as reliable as casting your string to a date object and putting that into your db. The second is just plain dumb for several reasons.
According to your situation, I think you TextBox in the FormView must be in that form of "dd-MM-yyyy", so you can use something like an AJAX Calendar that help you to force you input the value in a correct formation.
afastars
Member
52 Points
221 Posts
Change Date Format Before Insert Into Database
Dec 15, 2012 09:00 AM|LINK
hi all expertise,
i need to convert datetime before insert into database by using this format dd-MM-yyyy
below is my query, i need help, i really new in sql query
the bold word is my date
Dim commandString As String = "INSERT INTO KesalahanDisiplin" & _ "(IdPelajar,NoIc,KategoriKes,SubKes,Jam,Minit,Waktu,TarikhKes,TempatKejadian,PuncaSalahLaku,MaklumIbuBapa,TindakanPenjaga,SiaranMedia,KeteranganKes,PengesahanDisiplin,AduanOleh)" & _ "VALUES(@IdPelajar,@NoIc,@KategoriKes,@SubKes,@Jam,@Minit,@Waktu,@TarikhKes,@TempatKejadian,@PuncaSalahLaku,@MaklumIbuBapa,@TindakanPenjaga,@SiaranMedia,@KeteranganKes,@PengesahanDisiplin,@AduanOleh)"usman400
Contributor
3503 Points
721 Posts
Re: Change Date Format Before Insert Into Database
Dec 15, 2012 04:43 PM|LINK
I suggest you should use default format for date time that is supported in SQL Server, for displaying
to user, you can play with it in any format you like.
I have had problems in managing my own custom format of date in the database, I think you must
declare the field as varchar as SQL server wont allow you to store the date in non-SQL DateTime column format !
And after reading ur post I think u dont care for the time, so the best way is to use SQL Server's own date format
and in your query, you can build like that
RameshRajend...
Star
7983 Points
2099 Posts
Re: Change Date Format Before Insert Into Database
Dec 15, 2012 04:46 PM|LINK
hai
try this way
string value=YourDate.ToString("dd-MM-yyyy");
then you assign the value in your query.......
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Change Date Format Before Insert Into Database
Dec 15, 2012 06:22 PM|LINK
As soon as you start talking about formats you are talking about strings. This is relevent when you are displaying a date.
If you are writing to a database table, any discussion about formatting means you are doing something unwise. Either you are trying to put a string into a date field or you are storing dates in a char datatype. While the first might occasionally work, it's not as reliable as casting your string to a date object and putting that into your db. The second is just plain dumb for several reasons.
afastars
Member
52 Points
221 Posts
Re: Change Date Format Before Insert Into Database
Dec 15, 2012 10:29 PM|LINK
hi all expertise usman400, RameshRajendran, Dan Bracuk thanks for reply
my problem is , i'm using formview to update the user information, on date field i setup to this format {0:dd-MM-yyyy}
this is will appear as 28-12-2-12, so what happen is that when i want to update the user information i got errror
it because formview read my date is 12-28-2012 althought i setup the date will appear as 28-12-2012
on my database datatype i already setup datetime, on my insert webform i also already change the data type into datetime
so this is why i suspect during the inseration need to convert the date as what i want
if you have any other way how to resolve it you're please let me know expertise...i',m new in this concept
need to learn more
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Change Date Format Before Insert Into Database
Dec 15, 2012 11:04 PM|LINK
DateTime.ParseExact has an argument for the format. Use it on your string and send the DateTime object to your database.
afastars
Member
52 Points
221 Posts
Re: Change Date Format Before Insert Into Database
Dec 16, 2012 12:31 AM|LINK
hi Dan Bracuk
thanks for reply
where to put this..? on my formview ..?
really sorry i'm still in learning proses
afastars
Member
52 Points
221 Posts
Re: Change Date Format Before Insert Into Database
Dec 16, 2012 12:58 AM|LINK
hi Dan Bracuk
i think i got an idea, during the upate can i convert the date format as what i want...?
if can, i provide to you my query here, really don't know how to do it:
please look at the query below my date is a date that i want to convert to the date format like dd-MM-yyyy
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Change Date Format Before Insert Into Database
Dec 16, 2012 01:04 AM|LINK
Hi,
According to your situation, I think you TextBox in the FormView must be in that form of "dd-MM-yyyy", so you can use something like an AJAX Calendar that help you to force you input the value in a correct formation.
For AJAX's calendar, you can refer this:
<ajaxToolkit:Calendar runat="server" TargetControlID="Date1" CssClass="ClassName" Format="dd-MM-yyyy" PopupButtonID="Image1" />
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx
afastars
Member
52 Points
221 Posts
Re: Change Date Format Before Insert Into Database
Dec 16, 2012 01:06 AM|LINK
hi Decker Dong
will try it....