473,569 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime

Tom
Hi

There is a datetime type with length 8 in a table

I tried to insert the Local System datetime to it from aspx.cs file. But, the outcome are

string sysdatetime = System.DateTime .Now.ToShortDat eString(); //output 1900-01-01 00:00:00.000 in tabl
string sysdatetime = System.DateTime .Now.ToLongDate String(); //output 1900-01-01 00:00:00.000 in tabl
DateTime sysdatetime = System.DateTime .Now; //Compile error. Cannot convert char to datetim

They cannot output today datetime. How should I fix it

And, how can I get only Date 1900-01-01, only Time 00:00:00 or both DateTime 1900-01-01 00:00:00

Thanks
Nov 15 '05 #1
9 21078
play with "custom DateTime Format Strings" (refer to MSDN for complete
description)

in your case:
DateTime.Now.To String("yyy-MM-dd");
DateTime.Now.To String("hh:mm:s s");

José

"Tom" <ke*****@yahoo. com> wrote in message
news:AD******** *************** ***********@mic rosoft.com...
Hi,

There is a datetime type with length 8 in a table.

I tried to insert the Local System datetime to it from aspx.cs file. But, the outcome are:
string sysdatetime = System.DateTime .Now.ToShortDat eString(); //output 1900-01-01 00:00:00.000 in table string sysdatetime = System.DateTime .Now.ToLongDate String(); //output 1900-01-01 00:00:00.000 in table DateTime sysdatetime = System.DateTime .Now; //Compile error. Cannot convert char to datetime
They cannot output today datetime. How should I fix it?

And, how can I get only Date 1900-01-01, only Time 00:00:00 or both DateTime 1900-01-01 00:00:00?
Thanks

Nov 15 '05 #2
Tom
Hi

I use the following syntax

System.DateTime .Now.ToString(" yyy-MM-dd hh:mm:ss")

The data in table changes from 1900-01-01 00:00:00.000 to 1/1/1900

It cannot retrieve the current datetime of the OS.
Nov 15 '05 #3
I'm not too sure what you are trying to do...
However, I made a mistake, it should be
System.DateTime .Now.ToString(" yyyy-MM-dd hh:mm:ss");

As I see it you store your info inside a dB. Do you use a store procedure to
do it?
Assuming yes and that you use a dateTime as sql type, you could do the
following:
...
// Get a command object and make it part of transaction if needed
SqlCommand SqlCmd = new SqlCommand("Upd ateCredentialsF orTarget",
m_dBConnect, m_dBTrans);

SqlCmd.CommandT ype = CommandType.Sto redProcedure;
SqlCmd.Paramete rs.Add("@myDate ", SqlDbType.DateT ime).Value = DateTime.Now;
// Execute the SP
SqlCmd.ExecuteN onQuery();

José

"Tom" <ke*****@yahoo. com> wrote in message
news:E7******** *************** ***********@mic rosoft.com...
Hi,

I use the following syntax:

System.DateTime .Now.ToString(" yyy-MM-dd hh:mm:ss");

The data in table changes from 1900-01-01 00:00:00.000 to 1/1/1900

It cannot retrieve the current datetime of the OS.

Nov 15 '05 #4
Tom <ke*****@yahoo. com> wrote:
I use the following syntax:

System.DateTime .Now.ToString(" yyy-MM-dd hh:mm:ss");

The data in table changes from 1900-01-01 00:00:00.000 to 1/1/1900

It cannot retrieve the current datetime of the OS.


When you say "table", what exactly is your context? Is it a DataTable?
If so, you should make the type of your column a DateTime rather than
String.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Tom
The table schema

userid int
registerdate datetime

The cs clas

protected System.DateTime CurDateTime
CurDateTime = System.DateTime .Now

The SQL i

INSERT INTO tablename (registerdate) values (this.CurDateTi me); //it returns erro

I did not use stored procedure

How should I fix it

Nov 15 '05 #6
Tom
I tried CurDateTime.ToS tring();

It insert 1/1/1900 as DateTime

Why not current date and time?
Nov 15 '05 #7
Tom
Sorry, I missed that I am using MS SQL 2000
Nov 15 '05 #8
My guess is that that date is the default datetime when an invalid
datetime format is passed. Look in the SQL docs for how the string
needs to be formatted, and then call the ToString("...") with the
proper format.

Austin Ehlers

On Thu, 26 Feb 2004 09:36:11 -0800, Tom <ke*****@yahoo. com> wrote:
I tried CurDateTime.ToS tring();

It insert 1/1/1900 as DateTime.

Why not current date and time?


Nov 15 '05 #9
Tom <ke*****@yahoo. com> wrote:
The table schema:

userid int 4
registerdate datetime 8

The cs class

protected System.DateTime CurDateTime;
CurDateTime = System.DateTime .Now;

The SQL is

INSERT INTO tablename (registerdate) values (this.CurDateTi me); //it
returns error

I did not use stored procedure.

How should I fix it?


You should use a parameter in your command instead, and then set the
value of the parameter to the DateTime value you want. That way the
drivers deal with all the conversions for you.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10

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

Similar topics

4
2517
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it should be used? I can make a datetime easily enough
16
10458
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only...
15
14257
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
3
4229
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the datatable feeding the datagrid control. Both are of the DateTime Type. How do I get the time field to display only the Time, and not the date, which...
6
8971
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference between date and datetime classes? Please, help
5
1987
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,DateTime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second); I keep getting the below error: Object reference not set to an instance of an object. I don't know what the problem...
26
2658
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM' How do i do that? Reny ---
11
7202
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why only that I have to listen to them because they know it better. They told also that in a business situation it is better to use...
9
4908
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"...
0
16481
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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...
0
7921
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. ...
0
8118
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...
0
7964
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...
0
5217
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...
0
3651
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...
1
2107
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
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.