473,399 Members | 3,106 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,399 software developers and data experts.

Extracting date/time from database

Sorry for posting .. just half a message but i pressed enter outside the input field :here is entire problem . tnx in advance

i'm trying to extract a datetime value from a mysql database.The feld is in format
yyyy-mm-dd 00:00:00 and the datareader extracts something like this '4/1/2007' ,i don't figure it out where i go wrong

i tried with allow zero datetime=true, but is not working , i tried all the possibilities .. i don't know where is the problem ..
i tried with DR.getDateTime(i)

my code is :
conn3.ConnectionString = myConnString
conn3.Open()
comanda.Connection = conn3
Dim sqlQueryCommand As New MySqlCommand("select * from " & table & " ;", conn3)
Dim DR As MySqlDataReader
DR= sqlQueryCommand.ExecuteReader()
While DR.Read
For i = 0 To DR.FieldCount - 1
Dim tip = DR.GetFieldType(i)
If tip.ToString = "System.DateTime" Then
Dim exacttime = DR.GetDateTime(i)
Console.write(exacttime)
End If
Next
End while
conn3.close()
Apr 16 '07 #1
5 1837
do u want the format yyyy/MM/dd
try this code..

exacttime.tostring("yyyy/MM/dd")

Expand|Select|Wrap|Line Numbers
  1. conn3.ConnectionString = myConnString
  2. conn3.Open()
  3. comanda.Connection = conn3
  4. Dim sqlQueryCommand As New MySqlCommand("select * from " & table & " ;", conn3)
  5. Dim DR As MySqlDataReader
  6. DR= sqlQueryCommand.ExecuteReader()
  7. While DR.Read
  8. For i = 0 To DR.FieldCount - 1
  9. Dim tip = DR.GetFieldType(i)
  10. If tip.ToString = "System.DateTime" Then
  11. Dim exacttime = DR.GetDateTime(i)
  12. Console.write(exacttime.tostring("yyyy/MM/dd")
  13. End If
  14. Next
  15. End while
  16. conn3.close()
  17.  
  18.  
  19.  
Apr 16 '07 #2
Hello again ..
I succeed in manage the datetime data receive from datareader..
i used a old method .. or not so optimal ..
If tip.ToString = "System.DateTime" Or tip.ToString = "System.TimeSpan" Then
Dim dataextrasa As MySql.Data.Types.MySqlDateTime = arata.GetDateTime(i).ToString
Dim ora As String = Nothing
Dim minut As String = Nothing
Dim secunda As String = Nothing
Dim luna As String = Nothing
Dim ziua As String = Nothing
If dataextrasa.Hour.ToString = "0" Or dataextrasa.Hour.ToString = Nothing Then
ora = "00"
Else
ora = dataextrasa.Hour.ToString
End If
If dataextrasa.Minute.ToString = "0" Or dataextrasa.Minute.ToString = Nothing Then
minut = "00"
Else
minut = dataextrasa.Minute.ToString
End If
If dataextrasa.Second.ToString = "0" Or dataextrasa.Second.ToString = Nothing Then
secunda = "00"
Else
secunda = dataextrasa.Second.ToString
End If
'aici tre sa pun un 0 la luna si la zi .. in caz de sunt mai mici k 10
If dataextrasa.Month.ToString.Length = 1 Then
luna = "0" & dataextrasa.Month.ToString
Else
luna = dataextrasa.Month.ToString
End If

If dataextrasa.Day.ToString.Length = 1 Then
ziua = "0" & dataextrasa.Day.ToString
Else
ziua = dataextrasa.Day.ToString
End If
Dim combin As String = dataextrasa.Year.ToString & "-" & luna & "-" & ziua & " " & ora & ":" & minut & ":" & secunda
Console.Write("'" & combin & "'")
End If


-i think is a good method .. is not so optimal .. i hope helps
Apr 16 '07 #3
Plater
7,872 Expert 4TB
I am not sure why you keep checking to see if the returned value is of type DateTime, I've never had to do any checks like that, ToString always worked just fine.

SQL (well at least MSSQL, pretty sure other implimentations have it as well) has a Convert function, I use it all the time and it doesn't involve much of anything.
http://msdn2.microsoft.com/en-us/library/ms187928.aspx

Convert it to the form you want and tell it to return like type varchar(20) or something. You'll get a type string in your code but it will be formated how you like it.
Apr 16 '07 #4
r035198x
13,262 8TB
Changed thread title.
Apr 16 '07 #5
tnx guys .. right now i make the final "makeup" before i upload the files on the sourceforge.net .. i hope is not a problem .. if i wrote this internet address here ..

is about a mysqldump like utility wrote in vb.net .using the mysql connector .. i hope will be usefull ..
Apr 16 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: v0lcan0 | last post by:
Any help on extracting the time part from the datetime field in SQL database. even though i had entered only the time part in the database when i extract the field it gives me only the date...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
3
by: Alfred | last post by:
Hi I would like to extract only 15 records at a time from the backend in alfabetic order. Click on a button and then the next 15. Reason data must come over a 56k modem. The data is not...
2
by: bill tie | last post by:
Suppose it's Oct. 2, 2004 and time is 03:01:27. I need a number (integer) that is in this form: days hours minutes seconds Using the example, the number will be: 2030127
1
by: skinnybloke | last post by:
Hi - I have a date field in a Access database in the format YYYY/MM/DD HH:MM I have set up 2 date parameters as below but only want to enter the date and not the time. If I do not enter the time...
6
by: Rico | last post by:
Hello, I'm creating an audit table and associated triggers to be able to capture any updates and deletes from various tables in the database. I know how to capture the records that have been...
2
seshu
by: seshu | last post by:
hi everybody i have a greate problem in taking the time in date time what iam doning here is if i want time iam using time(column name) and for date i am using date(column name)...
1
by: jerryyang_la1 | last post by:
I'm reading in a CSV and displaying using the code below: $users = file("text.txt"); echo "<table border='1' width='75%' align='center'>"; echo "<tr>"; echo "<td width='33%'...
4
by: dexter48 | last post by:
Hi I'm searching for a string occurance in a text file. I find the string ok and write the results to a log file. But on the line above is also some information I need. How can i get that. The string...
4
by: poolboi | last post by:
hi guys i've having some problem extracting data from a text file example if i got a text file with infos like: Date 2008-05-01 Time 22-10 Date 2008-05-01 Time 21-00 Date 2008-05-02 Time...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.