Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Date and time stamp from current date & time

I am trying to apply a date and time stamp showing date and time in the format:  yyyy-mm-dd hh:MM:ss  I want to be able to easily display rows in chronological order.  Could someone provide the following:

1)  Code snippet for retrieving the info from system date
2   defning and storing the column in sql server
0
garyinmiami2003
Asked:
garyinmiami2003
3 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
(1) Use the ToString() method of the DateTime() class:

        Dim strDate As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        MessageBox.Show(strDate)

    Notice that the Month is uppercase "MM", while the Minutes are lowercase "mm".  Also, I used uppercase "HH" for the hours, which gives you a 24 hour format resulting in values between 00 and 23.  If you want a twelve hour format then use lowercase "hh".  To add the AM/PM on the end, add "tt":

        Dim strDate As String = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt")

(2) I have no idea...   =(
0
 
RJeyaPrakashCommented:
hai

for 1) use DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss")

for 2) when defining a column as datetime, sql server stores the data with time values..



regards
jp
0
 
af4643Commented:
for 2) Make sure you specify the sort order in your query string..."...order by datecolumn"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now