Proc to get datevalue from "21/02/2015", "23:59:59" params

Share your advanced PureBasic knowledge/code with the community.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Proc to get datevalue from "21/02/2015", "23:59:59" params

Post by Zebuddi123 »

Hi to all I have a sql db that i needed to add a new table from existing date and a time table in different formats ( "21/02/2015", "23:59:59" ) so i came up with this little Procedure so i can quickly run through the db and and create and add the new table from the existing. It might be useful to others so thought I`d share.

Zebuddi. :)

Code: Select all

Procedure.i GetLongDate(date.s, date_delimeter.s, time.s, time_delimeter.s) 
	Macro _mSF(string, index, delimeter)
		Val(StringField(String, index, delimeter))
	EndMacro
	ProcedureReturn  Date(_mSF(date,3,date_delimeter),_mSF(date,2,date_delimeter),_mSF(date,1,date_delimeter),_mSF(time,1,time_delimeter),_mSF(time,2,time_delimeter),_mSF(time,3,time_delimeter))
EndProcedure


Example: 
nd = GetLongDate("21/02/2015", "/", "23:59:59", ":")

Debug nd
Debug FormatDate("%dd,%mm,%yyyy,%hh,%ii,%ss",nd )
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Proc to get datevalue from "21/02/2015", "23:59:59" para

Post by StarBootics »

I'm not sure to fully understand what you want to do but a simple ParseDate() will do the same thing :

Code: Select all

Debug ParseDate("%dd/%mm/%yyyy, %hh:%ii:%ss", "21/02/2015, 23:59:59")


Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Proc to get datevalue from "21/02/2015", "23:59:59" para

Post by Zebuddi123 »

Hi StarBootics Doh cant believe I missed that :oops: :lol: Thanks at least I learned something in the process "to put my brain in gear first" lol

I assumed :oops: the delimiter`s were fixed :lol: in parsedate() as I don't ever remember using it only quickly read about, as i just found out and tested they can be virtually anything even omitted.

Zebuddi. :)
malleo, caput, bang. Ego, comprehendunt in tempore
Post Reply