garyinmiami2003
asked on
DB2 To/From datetime - string date conversions
Problem with DB2 DATETIME data retrieved and placed in a vb.net string variable, then attempting to convert back to datetime in an update query.
Example:
A Datetime column has data that in a DB2 table. When retrieved and placed in a string variable, it looks like this: 1/1/1994 12:00:00 AM.
What do I need to do in the update query to have it in correct datetime format?
Could you also show a good way convert both to and from database (both directions)
Example:
A Datetime column has data that in a DB2 table. When retrieved and placed in a string variable, it looks like this: 1/1/1994 12:00:00 AM.
What do I need to do in the update query to have it in correct datetime format?
Could you also show a good way convert both to and from database (both directions)
db2's datetime format is called timestamp
the format of a timestamp is
YYYY-MM-DD-HH24.MI.SS.NNNN NN' where nnnnnn are nanoseconds
in order to convert from / to that value you can either use vb code, or use some db2 functions
db2 has the following built in functions to handle timestamp values :
year - extract the year
month - extractd the month
day- extract the day
plus you can use string function to built up the date such as
substr, posstr
can't really help you with the vb code, but i'm sure you know vb, if you asked this quesiton
the format of a timestamp is
YYYY-MM-DD-HH24.MI.SS.NNNN
in order to convert from / to that value you can either use vb code, or use some db2 functions
db2 has the following built in functions to handle timestamp values :
year - extract the year
month - extractd the month
day- extract the day
plus you can use string function to built up the date such as
substr, posstr
can't really help you with the vb code, but i'm sure you know vb, if you asked this quesiton
ASKER
momi sabag:
the data example provided with the question is the result of DB2 data in DATE format (my orignal mistake) being moved to a datagrid and later in a string variable. Now this character string I provided:
1/1/1994 12:00:00 AM is the way it looks in the text file. I need to update this back to the db2 table.
Could you provide the syntax to do that including the update query for the one field.
And over and above the question Can you suggest a good way to edit the data since it could be modified by the user? (the last is extra but appreciated)
the data example provided with the question is the result of DB2 data in DATE format (my orignal mistake) being moved to a datagrid and later in a string variable. Now this character string I provided:
1/1/1994 12:00:00 AM is the way it looks in the text file. I need to update this back to the db2 table.
Could you provide the syntax to do that including the update query for the one field.
And over and above the question Can you suggest a good way to edit the data since it could be modified by the user? (the last is extra but appreciated)
hi
can you tell me exactly the format of the date that the user provides ? since you wrote 1/1/1994 i can't know which is the month and which is the day
plus, in vb, can you set the date format of the data grid or does vb have a constant format that cannot be changed ?
can you tell me exactly the format of the date that the user provides ? since you wrote 1/1/1994 i can't know which is the month and which is the day
plus, in vb, can you set the date format of the data grid or does vb have a constant format that cannot be changed ?
ASKER
it is displayed in USA format MM/dd/yyyy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim strDate as String
strDate = DatePart(DateInterval.Mont
strDate = strDate & "/" & DatePart(DateInterval.Day,
strDate = strDate & "/" & DatePart(DateInterval.Year