?
Solved

ASP.net VB.net SQL storing date and time

Posted on 2013-10-24
3
Medium Priority
?
488 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
colly92002 earned 2000 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:Murray Brown
ID: 39597146
thanks
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

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…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

771 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