Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a String to DateTime

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
I have a 20 character string in a field which needs to be converted to a datetime value using 24hour format.

The DateTimeValue requires a string, but this is coming from a field which is string 20.

Thanks,

Leo ;-)
 
I convert lots of strings to dates... here is one sql example.

convert (datetime, (nullif(substring (o2.OrderSubmittalDate , 6, 2) +"/" +
substring (o2.OrderSubmittalDate , 9, 2) + "/"+
substring(o2.OrderSubmittalDate , 1, 4) + " " +
substring(o2.OrderSubmittalDate , 12, 12), "//")

You just need to look at your string and see how it is formated to break up the string into something that you can convert to a date.

Once it is a date... you format the display to be 24 hr clock.

Lisa
 
lyanch gives a great example of how to do this in SQL.

You can do the same within CR by using the date() function, and parsing the date string appropriately to accomodate:

datetime('2002/02/12 12:23:34') returns:

Right click it and use format field to set it to a military time.

So you'd use the mid() function to parse and create the text to be used with the datetime function.

You might just try the datetime field against it and see what it gives you before worrying over the parsing.

-k kai@informeddatadecisions.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top