Solved

ASP.net VB.net SQL storing date and time

Posted on 2013-10-24
3
476 Views
Last Modified: 2013-10-24
Hi

I have a SQL table with a field that is Date type
I use the following code to get today's date and insert it into the table

Dim strDate As String = Now.Date.ToString

In the table I see eg 12/10/2013 12:00:00

How do I store the date and the exact time of entry?
Also, how do I store just the date in the table?
0
Comment
Question by:murbro
3 Comments
 
LVL 15

Accepted Solution

by:
colly92002 earned 500 total points
ID: 39596879
Have you tried using a format pattern?  
For example something like this:

' Get date now
Dim dispDt As DateTime = DateTime.Now

 ' Set up a date time format
Public Shared datePatt As String = "M/d/yyyy hh:mm:ss tt" 

Dim strDate As String
'Turn date/time into string using patter defined
 strDate = dispDt.ToString(datePatt)

Open in new window

0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39597141
as an alternative, you can get the current date and time directly in your insert sql:

insert into tblName( dateField ), value( getDate() );
0
 

Author Closing Comment

by:murbro
ID: 39597146
thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question