Solved

datagrid formatting problem!

Posted on 2002-03-13
6
213 Views
Last Modified: 2010-05-02
i got a datagrid which i want to show the date
as "dd-mm-yyyy hh:mm:ss". the data in the sql server table
is defined as datatime. however, when i select the data
into a datagrid my data->
"01-12-2001 00:00:00" becomes "01-12-2001" in the datagrid. It just never shows the "00:00:00"
but if the data is "01-12-2001 23:59" it shows the data
in its orginal form eg '01-12-2001 23:59". how to solve this problem i have?
0
Comment
Question by:spiral
[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
6 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6863251
Not very sure if this can work for SQL Server:

Select Format(myDate,'dd-mm-yyyy hh:mm:ss') As myDate From myTable
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6863451
Well, I just did this:
1. Right click on the grid, select Properties.
2. Click the Format Tab
3. Select the date/time column from Format Item Combo.
4. Select Format Type = Custom
5. Format string text box appears, create a mask.  Mine looks like:
dd-mm-yyyy hh:mm:ss

The column data looks like:
01-02-2002 00:00:00
01-02-2002 01:01:01
02-02-2002 12:59:00
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6863592
Please maintain your open questions:
Questions Asked 17
Last 10 Grades Given B A A B A B B B B  
Question Grading Record 9 Answers Graded / 9 Answers Received

Thanks,
Anthony
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:sunyuchen
ID: 6863678
maybe u can try this in sql statement
select convert(varchar, myDate, 109) from tblTime
0
 

Author Comment

by:spiral
ID: 6863711


the answer which being propose doesnt work
0
 
LVL 1

Accepted Solution

by:
cnealy earned 70 total points
ID: 6865377
I'm doing something similar in one of my data grids.   I was able to format a date column by using the StdDataFormat.  Try changing the line where I have objFormat.Format = "mm/dd/yyy" to the format that you want.

Dim objFormat As StdDataFormat 'for using DataFormat

For Each c In dbgCourtHearings.Columns
  Select Case c.DataField
  Case "Court_Date_ID"
    c.Visible = False
  Case "Court_Hearing_Date"
    c.Width = 1100
    Set objFormat = New StdDataFormat
    objFormat.Format = "mm/dd/yyyy"
    Set c.DataFormat = objFormat
  Case "Court_Hearing_Time"
    c.Width = 1000
    'set time format
    Set objFormat = New StdDataFormat
    objFormat.Format = "Medium Time"
    Set c.DataFormat = objFormat
  Case "Hearing_Type_Description"
    c.Width = 2700
  End Select
Next c
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

719 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