473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.ToShortDateString(); //output 1900-01-01 00:00:00.000 in tabl
string sysdatetime = System.DateTime.Now.ToLongDateString(); //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 21009
play with "custom DateTime Format Strings" (refer to MSDN for complete
description)

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

José

"Tom" <ke*****@yahoo.com> wrote in message
news:AD**********************************@microsof t.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.ToShortDateString(); //output 1900-01-01 00:00:00.000 in table string sysdatetime = System.DateTime.Now.ToLongDateString(); //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("UpdateCredentialsForTarget",
m_dBConnect, m_dBTrans);

SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.Add("@myDate", SqlDbType.DateTime).Value = DateTime.Now;
// Execute the SP
SqlCmd.ExecuteNonQuery();

José

"Tom" <ke*****@yahoo.com> wrote in message
news:E7**********************************@microsof t.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.com>
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.CurDateTime); //it returns erro

I did not use stored procedure

How should I fix it

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

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.ToString();

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.CurDateTime); //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.com>
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
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...
16
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...
15
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" ...
3
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...
6
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...
5
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new...
26
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'...
11
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...
9
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.