Archive for July 20th, 2007

Extracting date and time from date/time format using Visual FoxPro

July 20, 2007

A good friend of mine has a problem of migrating records from MSAccess to two separate files where date/time format is his concern. 

The codes below will extract date and time from date/time format. 

 set talk off
set strictdate to 0
set century on

select 1
use sample
*****  structure of sample.dbf  *****
*****  name character 10   *****
*****  d  datetime   8   *****

select 2
use datesample
*****  structure of datesample.dbf *****
*****  name character 10   *****
*****  date character 10   *****

select 3
use timesample
*****  structure of timesample.dbf *****
*****  name character 10   *****
*****  time character 11   *****

date2 = Ctod(“/”)
time2 = Ctot(“/:”)
cname=space(10)
t = space(22)

select 1
go top
do while !eof()

   if month(d)=7 and year(d)=2007
       date2=d
     time2=d
       t = right(ttoc(time2 ),11)
       cname=name
 
     select 2
     append blank
     replace name with cname, date with dtoc(date2)
 
     select 3
     append blank
     replace name with cname, time with t
   endif  
  
   select 1
   skip  
  
enddo
close all


Design a site like this with WordPress.com
Get started