473,797 Members | 3,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to convert DateTime in short date and short time

Dear all,

I want to save my data into MS Access database Table which consist of
some fields with short date and short time formats.
I try to save data in to the said table and I am getting error that my
SQL statment is not correct.

string strSQL = @"INSERT INTO Activities ( Task,Day,Start, Finish )
VALUES ( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;

I think error is because i am not able to cast my variables correctly.

how can i convert my DateTime to short date and short Time formats???

regards,

Omer kamal
Nov 17 '05 #1
3 15827
Omar,

Use parameters (the rest should go automatic)

http://msdn.microsoft.com/library/de...eterstopic.asp

Be aware that you have in OleDb to add the parameters in the sequents of
occurence of your SQL string

I hope this helps,

Cor

"Omer kamal" <om**@rhrk.un i-kl.de> schreef in bericht
news:dg******** **@news.uni-kl.de...
Dear all,

I want to save my data into MS Access database Table which consist of some
fields with short date and short time formats.
I try to save data in to the said table and I am getting error that my SQL
statment is not correct.

string strSQL = @"INSERT INTO Activities ( Task,Day,Start, Finish ) VALUES
( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;

I think error is because i am not able to cast my variables correctly.

how can i convert my DateTime to short date and short Time formats???

regards,

Omer kamal

Nov 17 '05 #2
Omer kamal <om**@rhrk.un i-kl.de> wrote:
I want to save my data into MS Access database Table which consist of
some fields with short date and short time formats.
I try to save data in to the said table and I am getting error that my
SQL statment is not correct.

string strSQL = @"INSERT INTO Activities ( Task,Day,Start, Finish )
VALUES ( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;

I think error is because i am not able to cast my variables correctly.

how can i convert my DateTime to short date and short Time formats???


The trick is not to embed the values directly in the SQL in the first
place. Instead, use aparameterised command. See
http://www.pobox.com/~skeet/csharp/faq/#db.parameters

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
You should also be aware that date values are stored differnrtly in MS
Access, but the libray has methoids to convert both ways.

See:
DateTime.ToOADa te Method
DateTime.FromOA Date Method

Paul V. Sullivan
On Mon, 12 Sep 2005 05:55:35 +0200, Omer kamal <om**@rhrk.un i-kl.de>
wrote:
Dear all,

I want to save my data into MS Access database Table which consist of
some fields with short date and short time formats.
I try to save data in to the said table and I am getting error that my
SQL statment is not correct.

string strSQL = @"INSERT INTO Activities ( Task,Day,Start, Finish )
VALUES ( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;

I think error is because i am not able to cast my variables correctly.

how can i convert my DateTime to short date and short Time formats???

regards,

Omer kamal


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3248
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert value to a time value' error. It's related to glibc returning an error to a pre-1970 date, I think. My question: /how/ do I go through the Python direction I've created to remove the pre-1970 date objects? Ideally, I would be able to iterate...
5
16337
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
5
18726
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
2
16361
by: Rob Roberts | last post by:
I have a GridView that is bound to a collection of DateTimes (i.e. - Collection<DateTime>). I have a BoundField in the GridView, and its DataField is set to the DateTime's Date property, and the DataFormatString is set to "{0:d}" in order to display the date in short date format (without the time). But the DataFormatString doesn't seem to have any effect. The DateTime gets displayed with the time. I have another GridView that is bound...
17
71459
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
2
5739
by: aqmaiya | last post by:
Hello, there is string value 'Dec 06, 2000' I want to convert that string date to SHORT FORMAT like '2000-12-06-. Please help me how do I do that? I'm new in Jython. Thanks, aqmaiya
2
12009
by: kirke | last post by:
Hi, I have a datetime column named dtDateTime. its format is "Oct 27 2006 12:00:00 " I want to group by only date part of it and count my code is $sql1="SELECT convert(varchar,J1708Data.dtDateTime,120), count(convert(varchar,J1708Data.dtDateTime,120))
0
1652
by: RSH | last post by:
Hi, I have a situation where I am using a dataset from a SQL Query. SQL's DateTime is a "long date/time field" which includes the Date/Time. My fields need to be displayed in a short time format "08:00" instead of "1/1/1900 08:00 AM"? I can't alter the database table, I only want to change the displayed value. How do I either change the datatable's column datatype to a string...or specify the columns formatting? How can I achieve...
4
3023
by: =?Utf-8?B?YW5kcmV3?= | last post by:
I am running an ASP.net program written in VB. At one point I try to convert a date string into a date time object... this string is from a central dev server and the code works on many other machines. Convert.ToDateTime("") I get the string in the format MM/DD/YYYY (06/26/2007) The code breaks and I get the "String was not recognized as a valid DateTime" error message unless I manually change the input string to
0
9537
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
10469
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...
1
10209
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
10023
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
9066
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...
0
6803
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
5459
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
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

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.