473,385 Members | 1,218 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,385 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 21041
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: 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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.