473,385 Members | 1,379 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.Now - Does't give seconds.

DateTime tTime = DateTime.Now;
-------------------------------------------------------------------------------------------
tTime returns "1:59:00 PM" it never returns seconds.

Database field is SQL datetime or smalldatetime.

Apr 9 '07 #1
7 13302
Actually, it does. 00 is the seconds. This is reflected in the Second
property on the DateTime structure.

Now, given that you are getting this from a database, it's possible that
you are not storing the seconds in the database in the first place. But the
DateTime structure in .NET most definitely does have a mechanism to get the
seconds at a point in time.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"TheLostLeaf" <er**@canyondigital.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
DateTime tTime = DateTime.Now;
-------------------------------------------------------------------------------------------
tTime returns "1:59:00 PM" it never returns seconds.

Database field is SQL datetime or smalldatetime.

Apr 9 '07 #2
DateTime tTime = DateTime.Now;
Console.WriteLine(tTime.Hour.ToString());
Console.WriteLine(tTime.Second.ToString());
Console.WriteLine(tTime.Millisecond.ToString());

Cheers,
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"TheLostLeaf" wrote:
DateTime tTime = DateTime.Now;
-------------------------------------------------------------------------------------------
tTime returns "1:59:00 PM" it never returns seconds.

Database field is SQL datetime or smalldatetime.

Apr 9 '07 #3
Sorry my post was so short, i didn't explain it properly.

I am trying to store the date time in the database, I was only
pointing our that the SQL field was not the issue with ommitting the
seconds.

I am just trying to get a DateTime string into the database (datetime
field) so that it includes the seconds.

For instance i am getting this
"1:59:00 PM"

and I want to get this

"1:59:29 PM"

Do I have to break it down into hours,minutes,seconds and re-
concantenate it ?
Thanks
-

Apr 9 '07 #4
No, you don't, but without seeing how you are inserting the value into
the database it's hard to say.

If you are using the datetime type in SQL Server, you should see second
values. The smalldatetime does not have second values, it will only show up
to minutes. From the documentation for Date and Time:

The smalldatetime data type stores dates and times of day with less
precision than datetime. The Database Engine stores smalldatetime values as
two 2-byte integers. The first 2 bytes store the number of days after
January 1, 1900. The other 2 bytes store the number of minutes since
midnight.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"TheLostLeaf" <er**@canyondigital.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.com...
Sorry my post was so short, i didn't explain it properly.

I am trying to store the date time in the database, I was only
pointing our that the SQL field was not the issue with ommitting the
seconds.

I am just trying to get a DateTime string into the database (datetime
field) so that it includes the seconds.

For instance i am getting this
"1:59:00 PM"

and I want to get this

"1:59:29 PM"

Do I have to break it down into hours,minutes,seconds and re-
concantenate it ?
Thanks
-

Apr 9 '07 #5
"TheLostLeaf" <er**@canyondigital.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.com...
Sorry my post was so short, i didn't explain it properly.

I am trying to store the date time in the database, I was only
pointing our that the SQL field was not the issue with ommitting the
seconds.

I am just trying to get a DateTime string into the database (datetime
field) so that it includes the seconds.
If you're losing seconds when the DateTime is stored in the database it's
because of the way you are storing or retriving the DateTime. I have no
problems storing DateTime fields in SQL datetime fields (and I get seconds
and fractions).

If you're using SQL smalldatetime then, that only stores minutes.
>
Do I have to break it down into hours,minutes,seconds and re-
concantenate it ?
No, you don't.

To retrieve I use:

DateTime myDateTime = dr.GetDateTime("myDateTime")

(Where dr is an open IDataReader)

To store I use:

updateCmd.Parameters.Add(new SqlParameter("@dtName", myDateTime))

Note that you have to make sure that myDateTime is within SQLs datetime
range which is smaller than a .NET DateTime.


Apr 9 '07 #6
Hmmm,

I think I figured it out. DateTime.Now does display the seconds, but
my data access layer must be ommiting them in a conversion somewhere.

It may be that I am using LLBLGen for my data layer.

Thanks for the feedback !!!
Apr 9 '07 #7
Ok I figured it out.

Since I was using LLBLGen to generate the C# Data access layer, my
original build had the field as smalldatetime, so the Layer retained
that conversion, even though I changed the SQL field to datetime. When
I rebuilt the Data Access Layer with the field as datetime, it workeds
perfect.

In the end i didn't realize smalldatetime eliminated seconds which was
the root of the problem, I though it only eliminated milliseconds..

Thanks for all the help ----

C# Noob pwnd by OO

Apr 9 '07 #8

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

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
3
by: nriesch | last post by:
In the documentation, the "Second" property of class DateTime is a value between 0 and 59. In UTC time, approximately every year of so, a leap second is added at 00:00:00 UTC, so as to account...
1
by: Ron | last post by:
How can I find the difference in seconds of two DateTime objects. I have looked at the Subtract method but this gives me back another DateTime object. Thanks, Ron
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'...
5
by: Nikeman | last post by:
good day, I simply would like to know as to how I can parse seconds to convert them into equivalent DateTime representation. To be more persice, I have a DirectShow app written in VB.NET, with a...
2
by: John Reese | last post by:
Hi. >>> import time, calendar, datetime >>> n= 1133893540.874922 >>> datetime.datetime.fromtimestamp(n) datetime.datetime(2005, 12, 6, 10, 25, 40, 874922) >>> lt= _ >>>...
5
by: ujjc001 | last post by:
two variables declared in my proc: @DATE_RANGE_START as datetime, @DATE_RANGE_END as datetime, When I execute my SP it takes 34 seconds. When I change the variables to: @DATE_RANGE_START1 as...
6
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm just trying to test datetime functions: DateTime dt1 = "9/15/2007"; DateTime dt2 = "9/17/2007"; DateTime dtResult; dtResult = dt2 - dt1; The above is what i'm trying to say...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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.